Skip to content

Commit

Permalink
chore: simplified pull request details extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
leelaprasadv committed Dec 13, 2024
1 parent cb07cbd commit 826fc41
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/extensions/ci-info.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class CIInfoExtension extends BaseExtension {
this.#setRepositoryElement();
}
if (this.extension.inputs.show_repository_branch) {
if (this.ci.pull_request) {
if (this.ci.pull_request_name) {
this.#setPullRequestElement();
} else {
this.#setRepositoryBranchElement();
}
}
if (!this.extension.inputs.show_repository && !this.extension.inputs.show_repository_branch && this.extension.inputs.show_repository_non_common) {
if (this.ci.pull_request) {
if (this.ci.pull_request_name) {
this.#setRepositoryElement();
this.#setPullRequestElement();
} else {
Expand All @@ -80,7 +80,7 @@ class CIInfoExtension extends BaseExtension {
}

#setPullRequestElement() {
this.repository_elements.push({ label: 'Pull Request', key: this.ci.pull_request.name, value: this.ci.pull_request.url, type: 'hyperlink' });
this.repository_elements.push({ label: 'Pull Request', key: this.ci.pull_request_name, value: this.ci.pull_request_url, type: 'hyperlink' });
}

#setRepositoryBranchElement() {
Expand Down
8 changes: 2 additions & 6 deletions src/extensions/extensions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ export type ICIInfo = {
repository_commit_sha: string
branch_url: string
branch_name: string
pull_request: IPRInfo | boolean
pull_request_url: string
pull_request_name: string
build_url: string
build_number: string
build_name: string
user: string
}

export type IPRInfo = {
name: string
url: string
}
9 changes: 4 additions & 5 deletions src/helpers/ci/azure-devops.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function info() {
repository_commit_sha: ENV.BUILD_SOURCEVERSION,
branch_url: '',
branch_name: '',
pull_request: false,
pull_request_url:'',
pull_request_name: '',
build_url: ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID,
build_number: ENV.BUILD_BUILDNUMBER,
build_name: ENV.BUILD_DEFINITIONNAME,
Expand All @@ -25,10 +26,8 @@ function info() {
azure_devops.branch_name = azure_devops.repository_ref.replace('refs/heads/', '');

if (azure_devops.repository_ref.includes('refs/pull')) {
azure_devops.pull_request = {
url: azure_devops.repository_url + azure_devops.repository_ref.replace('refs/pull/', '/pull/'),
name: azure_devops.repository_ref.replace('refs/pull/', '').replace('/merge', '')
}
azure_devops.pull_request_url = azure_devops.repository_url + azure_devops.repository_ref.replace('refs/pull/', '/pull/');
azure_devops.pull_request_name = azure_devops.repository_ref.replace('refs/pull/', '').replace('/merge', '');
}
return azure_devops;
}
Expand Down
9 changes: 4 additions & 5 deletions src/helpers/ci/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function info() {
repository_commit_sha: ENV.GITHUB_SHA,
branch_url: '',
branch_name: '',
pull_request: false,
pull_request_url:'',
pull_request_name: '',
build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID,
build_number: ENV.GITHUB_RUN_NUMBER,
build_name: ENV.GITHUB_WORKFLOW,
Expand All @@ -25,10 +26,8 @@ function info() {
github.branch_name = github.repository_ref.replace('refs/heads/', '');

if (github.repository_ref.includes('refs/pull')) {
github.pull_request = {
url: github.repository_url + github.repository_ref.replace('refs/pull/', '/pull/'),
name: github.repository_ref.replace('refs/pull/', '').replace('/merge', '')
}
github.pull_request_url = github.repository_url + github.repository_ref.replace('refs/pull/', '/pull/');
github.pull_request_name = github.repository_ref.replace('refs/pull/', '').replace('/merge', '');
}

return github
Expand Down
11 changes: 5 additions & 6 deletions src/helpers/ci/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ function info() {
git: 'GITLAB',
repository_url: ENV.CI_PROJECT_URL,
repository_name: ENV.CI_PROJECT_NAME,
repository_ref: ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || (`/-/tree/` + ENV.CI_COMMIT_REF_NAME),
repository_ref: '/-/tree/' + (ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME),
repository_commit_sha: ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA,
branch_url: ENV.CI_PROJECT_URL + '/-/tree/' + (ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH),
branch_name: ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH,
pull_request: false,
pull_request_url:'',
pull_request_name: '',
build_url: ENV.CI_JOB_URL,
build_number: ENV.CI_JOB_ID,
build_name: ENV.CI_JOB_NAME,
Expand All @@ -23,10 +24,8 @@ function info() {

if (ENV.CI_OPEN_MERGE_REQUESTS) {
const pr_number = ENV.CI_OPEN_MERGE_REQUESTS.split("!")[1];
gitlab.pull_request = {
name: ENV.CI_OPEN_MERGE_REQUESTS ? "#" + pr_number : "",
url: ENV.CI_PROJECT_URL + "/-/merge_requests/" + pr_number
}
gitlab.pull_request_name = "#" + pr_number;
gitlab.pull_request_url = ENV.CI_PROJECT_URL + "/-/merge_requests/" + pr_number;
}

return gitlab
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/ci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function getDefaultInformation() {
repository_commit_sha: ENV.TEST_BEATS_CI_REPOSITORY_COMMIT_SHA,
branch_url: ENV.TEST_BEATS_BRANCH_URL,
branch_name: ENV.TEST_BEATS_BRANCH_NAME,
pull_request: ENV.TEST_BEATS_PR || false,
pull_request_url: ENV.TEST_BEATS_PULL_REQUEST_URL,
pull_request_name: ENV.TEST_BEATS_PULL_REQUEST_NAME,
build_url: ENV.TEST_BEATS_CI_BUILD_URL,
build_number: ENV.TEST_BEATS_CI_BUILD_NUMBER,
build_name: ENV.TEST_BEATS_CI_BUILD_NAME,
Expand Down
9 changes: 4 additions & 5 deletions src/helpers/ci/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function info() {
repository_commit_sha: ENV.GIT_COMMIT || ENV.GIT_COMMIT_SHA || ENV.GITHUB_SHA || ENV.BITBUCKET_COMMIT,
branch_url: '',
branch_name: '',
pull_request: false,
pull_request_url:'',
pull_request_name: '',
build_url: ENV.BUILD_URL,
build_number: ENV.BUILD_NUMBER,
build_name: ENV.JOB_NAME,
Expand All @@ -25,10 +26,8 @@ function info() {
jenkins.branch_name = jenkins.repository_ref.replace('refs/heads/', '');

if (jenkins.repository_ref.includes('refs/pull')) {
jenkins.pull_request = {
url: jenkins.repository_url + jenkins.repository_ref.replace('refs/pull/', '/pull/'),
name: jenkins.repository_ref.replace('refs/pull/', '').replace('/merge', '')
}
jenkins.pull_request_url = jenkins.repository_url + jenkins.repository_ref.replace('refs/pull/', '/pull/');
jenkins.pull_request_name = jenkins.repository_ref.replace('refs/pull/', '').replace('/merge', '');
}

return jenkins_info;
Expand Down

0 comments on commit 826fc41

Please sign in to comment.