Skip to content

Commit

Permalink
feat(actions): add repository-owner-is-organization action
Browse files Browse the repository at this point in the history
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
  • Loading branch information
neilime committed Feb 2, 2024
1 parent a9139fb commit 481e573
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/__shared-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
needs: linter
uses: ./.github/workflows/__test-action-matrix-outputs.yml

test-action-repository-owner-is-organization:
needs: linter
uses: ./.github/workflows/__test-action-repository-owner-is-organization.yml

test-action-slugify:
needs: linter
uses: ./.github/workflows/__test-action-slugify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Internal - Tests for repository-owner-is-organization action

on:
workflow_call:

jobs:
tests:
name: Tests for repository-owner-is-organization action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- id: repository-owner-is-organization
uses: ./actions/repository-owner-is-organization

- name: Check repository-owner-is-organization outputs
run: |
if [ "${{ steps.repository-owner-is-organization.outputs.is-organization }}" != 'true' ]; then
echo "repository-owner-is-organization outputs result is not valid"
exit 1
fi
40 changes: 40 additions & 0 deletions actions/repository-owner-is-organization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- start branding -->
<!-- end branding -->
<!-- start title -->

# GitHub Action: Repository owner is organization

<!-- end title -->
<!-- start badges -->
<!-- end badges -->
<!-- start description -->

Action to check if the repository owner is an organization.

<!-- end description -->
<!-- start contents -->
<!-- end contents -->
<!-- start usage -->

```yaml
- uses: hoverkraft-tech/ci-github-common/actions/repository-owner-is-organization@v0.7.5
with:
```
<!-- end usage -->
<!-- start inputs -->
| **Input** | **Description** | **Default** | **Required** |
| ----------------------------- | ------------------------------------ | -------------------------------- | ------------ |
| **<code>github-token</code>** | GitHub token for fetching users API. | <code>${{ github.token }}</code> | **false** |
<!-- end inputs -->
<!-- start outputs -->
| **Output** | **Description** | **Default** | **Required** |
| ---------------------------- | ------------------------------------------------------------------------ | ----------- | ------------ |
| <code>is-organization</code> | The boolean value indicating if the repository owner is an organization. | undefined | undefined |
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
31 changes: 31 additions & 0 deletions actions/repository-owner-is-organization/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Repository owner is organization"
description: "Action to check if the repository owner is an organization."
author: Hoverkraft
branding:
icon: users
color: gray-dark

inputs:
github-token:
description: "GitHub token for fetching users API."
default: ${{ github.token }}
required: false

outputs:
is-organization:
description: "The boolean value indicating if the repository owner is an organization."
value: "${{ steps.check-org.outputs.is-organization }}"

runs:
using: "composite"
steps:
- id: check-org
run: |
OWNER_TYPE=$(curl -s -H "Authorization: token ${{ inputs.github-token }}" \
"https://api.github.com/users/${{ github.repository_owner }}" | jq -r .type)
if [ "$OWNER_TYPE" = "Organization" ]; then
echo "is-organization=true" >> "$GITHUB_OUTPUT"
fi
shell: bash

0 comments on commit 481e573

Please sign in to comment.