-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created BASIC rule implementation (#23)
## Basic rule Implemented the functionality of the basic rule. Because every rule ends up being simplified into: ```typescript { min_approvals: number; teams?: string[]; users?: string[]; } ``` I created a basic logic that evaluates that. After this, we can use the result of those smaller conditions to evaluate the more complex rules. I added a lot of tests and tried to do as many comments to explain the logic as possible. ## Teams API Created class which handles the teams token and obtains the team members of a team. This class is small but handles the token used for such authentication and separates the concern. If we decide to replace GitHub teams for on-chain data (like mentioned in paritytech/opstooling#245) this would let us to simply switch the implementation with minimal alterations. Closes #22 and closes #9
- Loading branch information
Showing
11 changed files
with
414 additions
and
17 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
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
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,40 @@ | ||
import { getOctokit } from "@actions/github"; | ||
|
||
import { ActionLogger, GitHubClient } from "./types"; | ||
|
||
/** | ||
* Interface for the acquisition of members of a team. | ||
* As we may be using blockchain instead of GitHub teams, let's wrap the functionality inside a interface | ||
*/ | ||
export interface TeamApi { | ||
/** Returns all the GitHub account's logins which belong to a given team. */ | ||
getTeamMembers(teamName: string): Promise<string[]>; | ||
} | ||
|
||
/** | ||
* Implementation of the TeamApi interface using GitHub teams | ||
* @see-also {@link TeamApi} | ||
*/ | ||
export class GitHubTeamsApi implements TeamApi { | ||
private readonly api: GitHubClient; | ||
|
||
/** Cache variable so we don't request the same information from GitHub in one run */ | ||
private readonly teamsCache: Map<string, string[]> = new Map<string, string[]>(); | ||
|
||
/** | ||
* @param teamOrgToken GitHub token with read:org access. It is used to access the organization team members | ||
* @param org Name of the organization the team will belong to. Should be available in context.repo.owner | ||
*/ | ||
constructor(teamOrgToken: string, private readonly org: string, private readonly logger: ActionLogger) { | ||
this.api = getOctokit(teamOrgToken); | ||
} | ||
|
||
async getTeamMembers(teamName: string): Promise<string[]> { | ||
// We first verify that this information hasn't been fetched yet | ||
if (this.teamsCache.has(teamName)) { | ||
return this.teamsCache.get(teamName) as string[]; | ||
} | ||
const { data } = await this.api.rest.teams.listMembersInOrg({ org: this.org, team_slug: teamName }); | ||
return data.map((d) => d.login); | ||
} | ||
} |
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
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
Oops, something went wrong.