Skip to content

Commit

Permalink
fix(platform-server): github comment to wrong issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Oct 28, 2022
1 parent 3ffe8f6 commit b731ed6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class GithubCheckSuiteProvider implements CheckSuiteProvider {

const installation = await this.github.getInstallationByRepository(action.project.namespace, action.project.name)
const accessToken = await this.github.getInstallationAccessToken(installation.id)
const repository = await this.github.getRepository(action.project.namespace, action.project.name, accessToken)

const params: GithubCheckRunParameters = {
name: `${action.project.slug} - ${checkName}`,
Expand All @@ -64,7 +65,7 @@ export class GithubCheckSuiteProvider implements CheckSuiteProvider {
accessToken,
params,
)
pullRequests = updated.pull_requests.map((pr) => ({ id: pr.id, number: pr.number }))
pullRequests = updated.pull_requests
} else {
const newCheckRun = await this.github.createCheckRun(
action.commitHash,
Expand All @@ -73,7 +74,7 @@ export class GithubCheckSuiteProvider implements CheckSuiteProvider {
accessToken,
params,
)
pullRequests = newCheckRun.pull_requests.map((pr) => ({ id: pr.id, number: pr.number }))
pullRequests = newCheckRun.pull_requests
await GithubCheckRunsAssociation.create({
checkId: checkId,
githubCheckRunId: newCheckRun.id,
Expand All @@ -83,6 +84,10 @@ export class GithubCheckSuiteProvider implements CheckSuiteProvider {
if (action.status === CheckStatus.completed && pullRequests.length > 0) {
const commentBody = params.output?.summary ?? ''
for (const pr of pullRequests) {
if (pr.base.repo.id !== repository.id) {
// skip pull requests not belong to this repository
continue
}
// TODO: need a lock here to prevent duplicate comment
const existedCommentId = (await GithubPullRequestsAssociation.findOneBy({ githubPullRequestId: pr.id }))
?.githubPullRequestCommentId
Expand Down
6 changes: 6 additions & 0 deletions packages/platform-server/src/modules/github/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ export interface GithubPullRequest {
head: {
ref: string
sha: string
repo: {
id: number
}
}
base: {
ref: string
sha: string
repo: {
id: number
}
}
}

Expand Down

0 comments on commit b731ed6

Please sign in to comment.