Skip to content

Commit 526131f

Browse files
committed
Add issue comment workflow
1 parent 7034aca commit 526131f

7 files changed

Lines changed: 105 additions & 16 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Process Issue Comment
2+
3+
on:
4+
issue_comment:
5+
types:
6+
- created
7+
8+
permissions:
9+
contents: write
10+
id-token: write
11+
issues: write
12+
13+
jobs:
14+
submit:
15+
name: Process Issue Comment
16+
runs-on: ubuntu-latest
17+
18+
if: |
19+
github.event.issue.state == 'open' &&
20+
(
21+
startsWith(github.event.comment.body, '.add-admin') ||
22+
startsWith(github.event.comment.body, '.add-user') ||
23+
startsWith(github.event.comment.body, '.remove-admin') ||
24+
startsWith(github.event.comment.body, '.remove-user')
25+
)
26+
27+
steps:
28+
- name: Get GitHub App Token
29+
id: token
30+
uses: actions/create-github-app-token@v1
31+
with:
32+
app-id: ${{ secrets.ISSUEOPS_APP_ID }}
33+
private-key: ${{ secrets.ISSUEOPS_APP_PEM_FILE }}
34+
owner: ${{ github.repository_owner }}
35+
36+
- name: Process IssueOps Request
37+
id: process
38+
uses: githubschool/gh-github-intermediate-issueops@main
39+
with:
40+
github_token: ${{ steps.token.outputs.token }}
41+
workspace: ${{ github.workspace }}

__tests__/actions.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ describe('actions', () => {
318318
})
319319

320320
it('Adds an Admin', async () => {
321+
mocktokit.graphql.mockResolvedValue({
322+
user: {
323+
isEmployee: true,
324+
email: 'noreply@github.com'
325+
}
326+
})
327+
321328
await actions.addAdmin(
322329
{
323330
action: AllowedIssueAction.CREATE,

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ export async function addAdmin(
109109
): Promise<void> {
110110
core.info(`Adding Admin to Class Request: #${payload.issue.number}`)
111111

112+
// Create the authenticated Octokit client.
113+
const token: string = core.getInput('github_token', { required: true })
114+
const octokit = github.getOctokit(token)
115+
112116
// Get the user from the comment body.
113117
// Format: .add-admin handle,email
114118
if (
@@ -123,6 +127,27 @@ export async function addAdmin(
123127
email: payload.comment.body.split(' ')[1].split(',')[1]
124128
}
125129

130+
// Check if the user is a GitHub/Microsoft employee.
131+
const response: { user: { isEmployee: boolean; email: string } } =
132+
await octokit.graphql(
133+
`
134+
query($login: String!) {
135+
user(login: $login) {
136+
isEmployee
137+
email
138+
}
139+
}
140+
`,
141+
{ login: user.handle }
142+
)
143+
144+
// Do not add the admin if they are not a GitHub or Microsoft employee.
145+
if (
146+
!response.user.isEmployee &&
147+
!response.user.email.includes('@microsoft.com')
148+
)
149+
throw new Error('Admins Must be GitHub/Microsoft Employees')
150+
126151
await teams.addUser(request, user, 'maintainer')
127152

128153
// Comment on the issue with the summary.
@@ -206,13 +231,13 @@ export async function removeAdmin(
206231
const response: { user: { isEmployee: boolean; email: string } } =
207232
await octokit.graphql(
208233
`
209-
query($login: String!) {
210-
user(login: $login) {
211-
isEmployee
212-
email
234+
query($login: String!) {
235+
user(login: $login) {
236+
isEmployee
237+
email
238+
}
213239
}
214-
}
215-
`,
240+
`,
216241
{ login: user.handle }
217242
)
218243

src/github/issues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export function generateMessage(request: ClassRequest): string {
289289
${request.attendees
290290
.map(
291291
(attendee) =>
292-
`| ${attendee.handle} | [\`${Common.OWNER}/${repos.generateRepoName(request, attendee)}\`](https://github.com/${Common.OWNER}/${attendee.handle}) |`
292+
`| ${attendee.handle} | [\`${Common.OWNER}/${repos.generateRepoName(request, attendee)}\`](https://github.com/${Common.OWNER}/${repos.generateRepoName(request, attendee)}) |`
293293
)
294294
.join('\n')}
295295

0 commit comments

Comments
 (0)