From 826fc4108bbcde88823efd9193331211f840fd2e Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:13:01 +0530 Subject: [PATCH] chore: simplified pull request details extraction --- src/extensions/ci-info.extension.js | 6 +++--- src/extensions/extensions.d.ts | 8 ++------ src/helpers/ci/azure-devops.js | 9 ++++----- src/helpers/ci/github.js | 9 ++++----- src/helpers/ci/gitlab.js | 11 +++++------ src/helpers/ci/index.js | 3 ++- src/helpers/ci/jenkins.js | 9 ++++----- 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/extensions/ci-info.extension.js b/src/extensions/ci-info.extension.js index 5086905..d775224 100644 --- a/src/extensions/ci-info.extension.js +++ b/src/extensions/ci-info.extension.js @@ -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 { @@ -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() { diff --git a/src/extensions/extensions.d.ts b/src/extensions/extensions.d.ts index b33946c..a944a83 100644 --- a/src/extensions/extensions.d.ts +++ b/src/extensions/extensions.d.ts @@ -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 } \ No newline at end of file diff --git a/src/helpers/ci/azure-devops.js b/src/helpers/ci/azure-devops.js index 56f1407..80dced1 100644 --- a/src/helpers/ci/azure-devops.js +++ b/src/helpers/ci/azure-devops.js @@ -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, @@ -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; } diff --git a/src/helpers/ci/github.js b/src/helpers/ci/github.js index 473cdb1..373661b 100644 --- a/src/helpers/ci/github.js +++ b/src/helpers/ci/github.js @@ -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, @@ -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 diff --git a/src/helpers/ci/gitlab.js b/src/helpers/ci/gitlab.js index 012b86a..e4a4b18 100644 --- a/src/helpers/ci/gitlab.js +++ b/src/helpers/ci/gitlab.js @@ -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, @@ -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 diff --git a/src/helpers/ci/index.js b/src/helpers/ci/index.js index 354e9e8..925ba41 100644 --- a/src/helpers/ci/index.js +++ b/src/helpers/ci/index.js @@ -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, diff --git a/src/helpers/ci/jenkins.js b/src/helpers/ci/jenkins.js index c0b875c..aaf5a9c 100644 --- a/src/helpers/ci/jenkins.js +++ b/src/helpers/ci/jenkins.js @@ -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, @@ -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;