|
| 1 | +name: Invite User to Organization |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + automate_invite: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout repository |
| 12 | + uses: actions/checkout@v3 |
| 13 | + |
| 14 | + - name: Get issue details |
| 15 | + id: issue |
| 16 | + run: echo "ISSUE_USER=${{ github.event.issue.user.login }}" >> $GITHUB_ENV |
| 17 | + |
| 18 | + - name: Send Organization Invitation |
| 19 | + run: | |
| 20 | + echo "Inviting user: $ISSUE_USER" |
| 21 | + RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X PUT \ |
| 22 | + -H "Authorization: token ${{ secrets.INVITE_TOKEN }}" \ |
| 23 | + -H "Accept: application/vnd.github.v3+json" \ |
| 24 | + "https://api.github.com/orgs/codameio/memberships/$ISSUE_USER" \ |
| 25 | + -d '{"role":"member"}') |
| 26 | + |
| 27 | + echo "GitHub API Response: $(cat response.json)" |
| 28 | + if [[ "$RESPONSE" -ne 200 && "$RESPONSE" -ne 201 ]]; then |
| 29 | + echo "Failed to send invitation" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Verify invitation status |
| 34 | + run: | |
| 35 | + echo "Checking if the user has been invited..." |
| 36 | + RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.INVITE_TOKEN }}" \ |
| 37 | + "https://api.github.com/orgs/codameio/invitations") |
| 38 | + echo "GitHub API Response: $RESPONSE" |
| 39 | +
|
| 40 | + - name: Post message and close the issue |
| 41 | + run: | |
| 42 | + ISSUE_NUMBER=${{ github.event.issue.number }} |
| 43 | + |
| 44 | + curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 45 | + -H "Accept: application/vnd.github.v3+json" \ |
| 46 | + -d "{\"body\": \"The invitation has been sent to @$ISSUE_USER to join the GitHub Organization. If you don't see it, please check your email or visit https://github.com/orgs/codameio/invitations.\"}" \ |
| 47 | + "https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments" |
| 48 | +
|
| 49 | + curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 50 | + -H "Accept: application/vnd.github.v3+json" \ |
| 51 | + -d '{"state": "closed"}' \ |
| 52 | + "https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER" |
0 commit comments