Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use default github token to fetch permissions #127

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __test__/command-helper.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('command-helper tests', () => {
const inputs: Inputs = {
token: '',
reactionToken: '',
githubToken: '',
reactions: true,
commands: commands,
permission: 'write',
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('command-helper tests', () => {
const inputs: Inputs = {
token: '',
reactionToken: '',
githubToken: '',
reactions: true,
commands: commands,
permission: 'admin',
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
reaction-token:
description: 'An optional GitHub token to use for reactions.'
default: ${{ github.token }}
github-token:
description: 'The default GitHub token.'
default: ${{ github.token }}
reactions:
description: 'Add reactions to comments containing commands.'
default: true
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function getInputs() {
return {
token: core.getInput('token'),
reactionToken: core.getInput('reaction-token'),
githubToken: core.getInput('github-token'),
reactions: core.getInput('reactions') === 'true',
commands: utils.getInputAsArray('commands'),
permission: core.getInput('permission'),
Expand Down Expand Up @@ -492,12 +493,13 @@ function run() {
// Create github clients
const githubHelper = new github_helper_1.GitHubHelper(inputs.token);
const githubHelperReaction = new github_helper_1.GitHubHelper(inputs.reactionToken);
const githubHelperPermission = new github_helper_1.GitHubHelper(inputs.githubToken);
// At this point we know the command is registered
// Add the "eyes" reaction to the comment
if (inputs.reactions)
yield githubHelperReaction.tryAddReaction(github.context.repo, commentId, 'eyes');
// Get the actor permission
const actorPermission = yield githubHelper.getActorPermission(github.context.repo, github.context.actor);
const actorPermission = yield githubHelperPermission.getActorPermission(github.context.repo, github.context.actor);
core.debug(`Actor permission: ${actorPermission}`);
// Filter matching commands by the user's permission level
configMatches = configMatches.filter(function (cmd) {
Expand Down
1 change: 1 addition & 0 deletions hello-world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello @han-dot-otsv!
2 changes: 2 additions & 0 deletions src/command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const MAX_ARGS = 50
export interface Inputs {
token: string
reactionToken: string
githubToken: string
reactions: boolean
commands: string[]
permission: string
Expand Down Expand Up @@ -77,6 +78,7 @@ export function getInputs(): Inputs {
return {
token: core.getInput('token'),
reactionToken: core.getInput('reaction-token'),
githubToken: core.getInput('github-token'),
reactions: core.getInput('reactions') === 'true',
commands: utils.getInputAsArray('commands'),
permission: core.getInput('permission'),
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async function run(): Promise<void> {
// Create github clients
const githubHelper = new GitHubHelper(inputs.token)
const githubHelperReaction = new GitHubHelper(inputs.reactionToken)
const githubHelperPermission = new GitHubHelper(inputs.githubToken)

// At this point we know the command is registered
// Add the "eyes" reaction to the comment
Expand All @@ -121,7 +122,7 @@ async function run(): Promise<void> {
)

// Get the actor permission
const actorPermission = await githubHelper.getActorPermission(
const actorPermission = await githubHelperPermission.getActorPermission(
github.context.repo,
github.context.actor
)
Expand Down