Skip to content

Commit d0c8010

Browse files
committed
Add comment for unauthorized users
1 parent bd93d04 commit d0c8010

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

__tests__/main.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ describe('main', () => {
9898
})
9999

100100
await main.run()
101-
expect(core.setFailed).toHaveBeenCalledWith(
102-
'You are not authorized to use this action. Please contact an instructor.'
103-
)
101+
102+
expect(mocktokit.rest.issues.createComment).toHaveBeenCalled()
104103
})
105104

106105
it('Skips Invalid Actions', async () => {

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

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

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gh-github-intermediate-issueops",
33
"description": "GitHub Intermediate Offering: IssueOps Automation",
4-
"version": "2.0.3",
4+
"version": "2.0.4",
55
"author": "Nick Alteen <[email protected]>",
66
"private": true,
77
"type": "module",

src/main.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,23 @@ export async function run(): Promise<void> {
2929

3030
// Check if the user is authorized to use this action.
3131
const user = github.context.actor
32-
if (!authorizedUsers.includes(user))
33-
return core.setFailed(
34-
`You are not authorized to use this action. Please contact an instructor.`
35-
)
32+
if (!authorizedUsers.includes(user)) {
33+
// Comment on the issue to let the user know they are not authorized.
34+
const token: string = core.getInput('github_token', { required: true })
35+
const octokit = github.getOctokit(token)
36+
37+
// Add the error comment to the request issue.
38+
await octokit.rest.issues.createComment({
39+
issue_number: (payload as IssueCommentEvent).issue.number,
40+
owner: Common.OWNER,
41+
repo: Common.ISSUEOPS_REPO,
42+
body: dedent(
43+
`Sorry @${github.context.actor}! You are not authorized to use this action. Please contact an instructor.`
44+
)
45+
})
46+
47+
return
48+
}
3649

3750
// Decide what action to take based on issue state and comment text.
3851
const action = events.getAction(eventName, payload)

0 commit comments

Comments
 (0)