diff --git a/CHANGELOG.md b/CHANGELOG.md index 548de6db8..a45c060f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta` +## [4.5.1] 2023-09-11 + +- GitHub Integration: Fix Quick Deploy on Pull Requests + ## [4.5.0] 2023-09-11 - GitHub Integration: Implement automated comments & Quick Deploy on Pull Requests diff --git a/docs/assets/images/screenshot-gha-error.jpg b/docs/assets/images/screenshot-gha-error.jpg new file mode 100644 index 000000000..660893f88 Binary files /dev/null and b/docs/assets/images/screenshot-gha-error.jpg differ diff --git a/src/common/gitProvider/github.ts b/src/common/gitProvider/github.ts index a1c1637ce..753123e5b 100644 --- a/src/common/gitProvider/github.ts +++ b/src/common/gitProvider/github.ts @@ -19,6 +19,40 @@ export class GithubProvider extends GitProviderRoot { return "sfdx-hardis GitHub connector"; } + public async getBranchDeploymentCheckId(gitBranch: string): Promise { + let deploymentCheckId = null; + const repoOwner = github?.context?.repo?.owner || null; + const repoName = github?.context?.repo?.repo || null; + const latestPullRequestsOnBranch = await this.octokit.rest.pulls.list({ + owner: repoOwner, + repo: repoName, + state: "closed", + direction: "desc", + per_page: 10, + base: gitBranch, + }); + if (latestPullRequestsOnBranch.data.length > 0) { + const latestPullRequest = latestPullRequestsOnBranch.data[0]; + const latestPullRequestId = latestPullRequest.id; + const existingComments = await this.octokit.rest.issues.listComments({ + owner: repoOwner, + repo: repoName, + issue_number: latestPullRequestId, + }); + for (const existingComment of existingComments.data) { + if (existingComment.body.includes("/gm.exec(existingComment.body); + if (matches) { + deploymentCheckId = matches[1]; + uxLog(this, c.gray(`Found deployment id ${deploymentCheckId} on PR #${latestPullRequestId} ${latestPullRequest.title}`)); + } + break; + } + } + } + return deploymentCheckId; + } + // Posts a note on the merge request public async postPullRequestMessage(prMessage: PullRequestMessageRequest): Promise { const { pull_request } = github.context.payload;