Skip to content
Merged
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: 1 addition & 1 deletion .github/workflows/issue-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
const username = '${{ github.actor }}'
const team = 'website-write'
const script = require('./github-actions/utils/check-team-membership.js')
return script(github, username, team)
return script(github, context, username, team)

# If user is team member: checks if the issue has required labels
- if: ${{ steps.check-team-membership.outputs.result == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion github-actions/trigger-pr-target/verify-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function main({github,context}) {
const prNumber = context.payload.number;
const repo = context.payload.pull_request.base.repo.name;
const owner = context.payload.pull_request.base.repo.owner.login;
const isMember = await isMemberOfTeam(github, prAuthor, 'website-write');
const isMember = await isMemberOfTeam(github, context, prAuthor, 'website-write');
if (isMember || prAuthor =='dependabot[bot]') {
console.log('Successfully verified!');
}
Expand Down
61 changes: 31 additions & 30 deletions github-actions/utils/check-team-membership.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
/**
* @param {octokit} github - Octokit object used to access GitHub API
* @param {String} githubUsername - The GitHub username of the user whose membership is to be checked.
* @param {String} team - The HFLA team the username's membership is checked against. Example: 'website-write'

- Returns true or false depending on whether the username is found on the passed team, 404 means the user passed wasn't
found on the team passed. Any other type of error will be thrown.
- Need read:org permission to use this function, the least permissive token which contains this is the TEAMS token.
Lack of permission will result in a 403 error.
- The method of obtaining the GitHub username will vary depending on the contents of the context object. See GitHub action
docs on printing context information into the log.
*/

async function isMemberOfTeam(github, githubUsername, team) {
try {
await github.rest.teams.getMembershipForUserInOrg({
org: 'hackforla',
team_slug: team,
username: githubUsername
});
console.log(`User '${githubUsername}' is member of team '${team}'`);
return true;
} catch (verificationError) {
if (verificationError.status == 404) {
console.log(`User '${githubUsername}' is not a team member`);
return false;
}
else {
throw verificationError;
}
/**
* @param {octokit} github - Octokit object used to access GitHub API
* @param {Object} context - context object from actions/github-script
* @param {String} githubUsername - The GitHub username of the user whose membership is to be checked.
* @param {String} team - The HFLA team the username's membership is checked against. Example: 'website-write'
*
* Returns true or false depending on whether the username is found on the passed team, 404 means the user passed
* wasn't found on the team passed. Any other type of error will be thrown.
*
* Need read:org permission to use this function. Lack of permission will result in a 403 error.
*
* The method of obtaining the GitHub username will vary depending on the contents of the context object. See GitHub
* action docs on printing context information into the log.
*/
async function isMemberOfTeam(github, context, githubUsername, team) {
try {
await github.rest.teams.getMembershipForUserInOrg({
org: context.repo.owner,
team_slug: team,
username: githubUsername
});
console.log(`User '${githubUsername}' is member of team '${team}'`);
return true;
} catch (verificationError) {
if (verificationError.status === 404) {
console.log(`User '${githubUsername}' is not a team member`);
return false;
} else {
throw verificationError;
}
}
}

module.exports = isMemberOfTeam;