This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support permission api * feat: add permission * chore: update package-lock.json * refactor: refine api * refactor: refine app * refactor: refine api url * refactor: rename * refactor: rename * refactor: rename * refactor: refine import order * refactor: remove useless comment * refactor: remove useless comment * refactor: add comment
- Loading branch information
Showing
15 changed files
with
1,442 additions
and
402 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Empty file.
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,96 @@ | ||
import { Request, Response } from "express"; | ||
import { ProbotOctokit } from "probot/lib/octokit/probot-octokit"; | ||
|
||
import { PullFileQuery } from "../../queries/PullFileQuery"; | ||
import { PullReviewersQuery } from "../../queries/PullReviewersQuery"; | ||
import { | ||
Config, | ||
DEFAULT_CONFIG_FILE_PATH, | ||
DEFAULT_SIG_INFO_FILE_NAME, | ||
} from "../../config/Config"; | ||
import { config } from "../../services/utils/ConfigUtil"; | ||
import { ContributorSchema } from "../../config/SigInfoSchema"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { PullMessage } from "../../services/messages/PullMessage"; | ||
import PullService from "../../services/pull"; | ||
|
||
const listReviews = async ( | ||
req: Request, | ||
res: Response, | ||
pullService: PullService, | ||
github: InstanceType<typeof ProbotOctokit> | ||
) => { | ||
// Collect params. | ||
const owner = req.params.owner; | ||
const repo = req.params.repo; | ||
const pullNumber = Number(req.params.number); | ||
|
||
const { data: filesData } = await github.pulls.listFiles({ | ||
owner, | ||
repo, | ||
pull_number: pullNumber, | ||
}); | ||
|
||
const files: PullFileQuery[] = filesData.map((f) => { | ||
return { | ||
...f, | ||
}; | ||
}); | ||
|
||
// Get config form repo. | ||
const repoConfig = await config<Config>( | ||
owner, | ||
repo, | ||
DEFAULT_CONFIG_FILE_PATH, | ||
github | ||
); | ||
|
||
// Because we need this config to get maintainer team. | ||
if (repoConfig === null) { | ||
res.status(StatusCodes.BAD_REQUEST); | ||
const response = { | ||
data: null, | ||
status: StatusCodes.BAD_REQUEST, | ||
message: PullMessage.ConfigNotFound, | ||
}; | ||
res.json(response); | ||
|
||
return; | ||
} | ||
|
||
// Get maintainers and repo collaborators. | ||
const { data: maintainerInfos } = await github.teams.listMembersInOrg({ | ||
org: owner, | ||
team_slug: repoConfig.maintainerTeamSlug, | ||
}); | ||
|
||
const maintainers: ContributorSchema[] = maintainerInfos.map((m) => { | ||
return { | ||
githubId: m.login, | ||
}; | ||
}); | ||
|
||
const { data: collaboratorInfos } = await github.repos.listCollaborators({ | ||
owner, | ||
repo, | ||
}); | ||
const collaborators = collaboratorInfos.map((c) => { | ||
return { | ||
githubId: c.login, | ||
}; | ||
}); | ||
|
||
const pullReviewersQuery: PullReviewersQuery = { | ||
sigInfoFileName: repoConfig.sigInfoFileName || DEFAULT_SIG_INFO_FILE_NAME, | ||
maintainers, | ||
collaborators, | ||
files, | ||
}; | ||
|
||
const response = await pullService.listReviewers(pullReviewersQuery); | ||
|
||
res.status(response.status); | ||
res.json(response); | ||
}; | ||
|
||
export default listReviews; |
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,9 @@ | ||
import { PullFileQuery } from "./PullFileQuery"; | ||
import { ContributorSchema } from "../config/SigInfoSchema"; | ||
|
||
export interface PullReviewersQuery { | ||
sigInfoFileName: string; | ||
files: PullFileQuery[]; | ||
maintainers: ContributorSchema[]; | ||
collaborators: ContributorSchema[]; | ||
} |
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,4 @@ | ||
export interface PullReviewersDTO { | ||
reviewers: string[]; | ||
needsLGTM: number; | ||
} |
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.