Skip to content

Commit

Permalink
Add member token
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenyomi committed Jan 14, 2024
1 parent 50b0497 commit b7c5167
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ jobs:
| Name | Description |
| ----------------- | ---------------------------------------------------------- |
| `repo-token` | GitHub access token |
| `member-token` | Token with read access to organization members |
| `duplicate-label` | Label to add on duplicate command and auto duplicate check |

If `member-token` is not provided, `repo-token` will be used to check user's membership. In this case, the action might fail to verify private members.

### Auto closers

| Name | Description |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
repo-token:
required: true
description: GitHub token
member-token:
required: false
description: Token with read access to organization members
duplicate-label:
required: false
description: Label to add on duplicate command and auto duplicate check
Expand Down
56 changes: 28 additions & 28 deletions dist/index.js

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions src/feature/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,16 @@ export async function checkForCommand() {
core.getInput('repo-token', { required: true }),
);

// Get all the members from the organization.
const allowedMembers = await client.rest.orgs.listMembers({
org: repo.owner,
});
if (allowedMembers.status !== 200) {
core.info('Failed to fetch the members from the organization');
return;
}
if (
!allowedMembers.data.find((member) => member.login === commentUser.login)
) {
core.info('The comment author is not a organization member');
try {
const memberToken = core.getInput('member-token');
const memberClient = memberToken ? github.getOctokit(memberToken) : client;

await memberClient.rest.orgs.checkMembershipForUser({
org: repo.owner,
username: commentUser.login,
});
} catch (_) {
core.info('Could not verify the membership of the comment author');
return;
}

Expand Down

0 comments on commit b7c5167

Please sign in to comment.