Issue Workflow
Once a user submits your issue form, its time for GitHub Actions to run the show! The issue workflow is responsible for performing any initial processing of the issue such as adding labels, validating the contents, adding comments, etc. The following sections will walk through the core structure of an issue workflow.Event triggers
Most of the time, this workflow will only be run when an issue is opened or edited, however there are some cases where you may want to run this workflow when an issue is reopened.1on:
2 issues:
3 types:
4 - opened
5 - edited
6 - reopened
Jobs
Different request types may have different inputs. For example, a new repository request may have different inputs than a repository transfer request. If you decide to create multiple jobs to parse different types of requests in the same workflow, you can use labels to control which jobs run for which types of requests.You should also consider how you plan to handle processing of multiple requests in the same workflow.1jobs:
2 new-repository-request:
3 name: New Repository Request
4 runs-on: ubuntu-latest
5
6 # Only run for issues with the `issueops:new-repository` label.
7 if: contains(github.event.issue.labels.*.name, 'issueops:new-repository')
8
9 team-membership-request:
10 name: Team Membership Request
11 runs-on: ubuntu-latest
12
13 # Only run for issues with the `issueops:team-add` label.
14 if: contains(github.event.issue.labels.*.name, 'issueops:team-add')
Depending on the complexity of your workflow, you may want to isolate each type of request to separate jobs entirely, or you may want to have jobs that handle common tasks across multiple request types. For example, if you have IssueOps workflows for adding and removing users from a team, there's a good chance they both have the same input data and perform the same validation steps. In this case, you may want to create a job that handles the common tasks, and then have separate jobs for the unique tasks.1jobs:
2 team-request:
3 name: Team Management Request
4 runs-on: ubuntu-latest
5
6 # Run this job for both request types
7 if: |
8 contains(github.event.issue.labels.*.name, 'issueops:team-add') ||
9 contains(github.event.issue.labels.*.name, 'issueops:team-remove')
10
11 outputs:
12 request: ${{ steps.parse.outputs.json }}
13
14 steps:
15 - name: Parse Issue
16 id: parse
17 uses: issue-ops/parser@vX.X.X
18 with:
19 body: ${{ github.event.issue.body }}
20 issue-form-template: team-add-remove-request.yml
21
22 - name: Validate Issue
23 id: validate
24 uses: issue-ops/validator@vX.X.X
25 with:
26 issue-form-template: team-add-remove-request.yml
27 parsed-issue-body: ${{ steps.parse.outputs.json }}
28
29 team-add:
30 name: Team Add Request
31 runs-on: ubuntu-latest
32
33 # Only run after the `team-request` job has completed
34 needs: team-request
35
36 # Only run for issues with the `issueops:team-add` label.
37 if: contains(github.event.issue.labels.*.name, 'issueops:team-add')
38
39 steps:
40 - name: Add User to Team
41 id: add
42 uses: actions/github-script@vX.X.X
43 with:
44 github-token: ${{ secrets.MY_TOKEN }}
45 script: |
46 const request = JSON.parse('${{ needs.team-request.outputs.request }}')
47
48 await github.rest.teams.addOrUpdateMembershipForUserInOrg({
49 org: request.org,
50 team_slug: request.team,
51 username: request.user
52 })
53
54 team-remove:
55 name: Team Remove Request
56 runs-on: ubuntu-latest
57
58 # Only run after the `team-request` job has completed
59 needs: team-request
60
61 # Only run for issues with the `issueops:team-remove` label.
62 if: contains(github.event.issue.labels.*.name, 'issueops:team-remove')
63
64 steps:
65 - name: Remove User from Team
66 id: remove
67 uses: actions/github-script@vX.X.X
68 with:
69 github-token: ${{ secrets.MY_TOKEN }}
70 script: |
71 const request = JSON.parse('${{ needs.team-request.outputs.request }}')
72
73 await github.rest.teams.removeMembershipForUserInOrg({
74 org: request.org,
75 team_slug: request.team,
76 username: request.user
77 })