Skip to content

Commit

Permalink
GitHub Integration: Fix Quick Deploy on Pull Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Sep 11, 2023
1 parent a7a201d commit 0f69838
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added docs/assets/images/screenshot-gha-error.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/common/gitProvider/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@ export class GithubProvider extends GitProviderRoot {
return "sfdx-hardis GitHub connector";
}

public async getBranchDeploymentCheckId(gitBranch: string): Promise<string> {
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("<!-- sfdx-hardis deployment-id ")) {
const matches = /<!-- sfdx-hardis deployment-id (.*) -->/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<PullRequestMessageResult> {
const { pull_request } = github.context.payload;
Expand Down

0 comments on commit 0f69838

Please sign in to comment.