-
-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility function, change API syntax
- Loading branch information
Showing
2 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @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 secrets.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 { | ||
const result = await github.rest.teams.getMembershipForUserInOrg({ | ||
Check notice Code scanning / CodeQL Unused variable, import, function or class Note
Unused variable result.
|
||
org : 'hackforla', | ||
team_slug : team, | ||
username : githubUsername | ||
}); | ||
return true; | ||
} catch (verificationError) { | ||
if (verificationError.status == 404) { | ||
return false; | ||
} | ||
else { | ||
throw verificationError; | ||
} | ||
} | ||
} | ||
|
||
module.exports = isMemberOfTeam; |