From 2c398e25dea9aca0a3b1aaf413dfb029f6de9f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 15 Dec 2023 23:15:03 +0100 Subject: [PATCH 01/15] Pointing GHA to issue branch --- ...create-jira-issues-for-community-activities-in-this-repo.yml | 2 +- .../workflows/create-jira-issues-for-community-activities.yml | 2 +- .github/workflows/post-pull-request-checks-automation.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml b/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml index 7b307e153..7a3d1fcff 100644 --- a/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml +++ b/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml @@ -11,7 +11,7 @@ on: jobs: create-jira-issues-for-community-activities: name: Create Jira issues for community activities - uses: Lombiq/GitHub-Actions/.github/workflows/create-jira-issues-for-community-activities.yml@dev + uses: Lombiq/GitHub-Actions/.github/workflows/create-jira-issues-for-community-activities.yml@issue/OSOE-726 secrets: JIRA_BASE_URL: ${{ secrets.DEFAULT_JIRA_BASE_URL }} JIRA_USER_EMAIL: ${{ secrets.DEFAULT_JIRA_USER_EMAIL }} diff --git a/.github/workflows/create-jira-issues-for-community-activities.yml b/.github/workflows/create-jira-issues-for-community-activities.yml index 05d8590cf..dd020f629 100644 --- a/.github/workflows/create-jira-issues-for-community-activities.yml +++ b/.github/workflows/create-jira-issues-for-community-activities.yml @@ -56,7 +56,7 @@ jobs: timeout-minutes: ${{ inputs.timeout-minutes }} steps: - name: Create Jira issues for community activities - uses: Lombiq/GitHub-Actions/.github/actions/create-jira-issues-for-community-activities@dev + uses: Lombiq/GitHub-Actions/.github/actions/create-jira-issues-for-community-activities@issue/OSOE-726 env: JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} diff --git a/.github/workflows/post-pull-request-checks-automation.yml b/.github/workflows/post-pull-request-checks-automation.yml index bbcaa3bab..c6161e09f 100644 --- a/.github/workflows/post-pull-request-checks-automation.yml +++ b/.github/workflows/post-pull-request-checks-automation.yml @@ -80,7 +80,7 @@ jobs: - name: Automatically Resolve or Done Jira issue if: steps.check-steps-should-run.outputs.is-latest != 'false' - uses: Lombiq/GitHub-Actions/.github/actions/auto-resolve-done-jira-issue@dev + uses: Lombiq/GitHub-Actions/.github/actions/auto-resolve-done-jira-issue@issue/OSOE-726 env: GITHUB_TOKEN: ${{ env.MERGE_TOKEN }} JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} From b2b9c76c99961ef8d8d7a42017b87555af25f737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 15 Dec 2023 23:27:34 +0100 Subject: [PATCH 02/15] Fixing docs link --- Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md index 8dfa50ca9..376a4bff0 100644 --- a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md +++ b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md @@ -5,7 +5,7 @@ Various automation that should be run after all other checks succeeded for a pul - Merges the current pull request if the "merge-and-resolve-jira-issue-if-checks-succeed" or "merge-if-checks-succeed" label is present. With prerequisite jobs you can execute this only if all others jobs have succeeded. Unlike [GitHub's auto-merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request), this works without branch protection rules. - Resolves the Jira issue corresponding to the pull request if the "resolve-jira-issue-if-checks-succeed" or "merge-and-resolve-jira-issue-if-checks-succeed" label is present, or sets the issue to Done if the "done-jira-issue-if-checks-succeed" label is. -See an example of how you can utilize this workflow, together with jobs that do other checks below. For configuring the `JIRA_*` secrets see the documentation of `create-jira-issues-for-community-activities` above, and for details on `MERGE_TOKEN` check out the workflow's inline documentation. +See an example of how you can utilize this workflow, together with jobs that do other checks below. For configuring the `JIRA_*` secrets see the [documentation of `create-jira-issues-for-community-activities`](CreateJiraIssuesForCommunityActivities.md), and for details on `MERGE_TOKEN` check out the workflow's inline documentation. ```yaml name: Build and Test From f9cd5a22669961676207675d66a78ae1063e172d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 00:43:20 +0100 Subject: [PATCH 03/15] Renaming JIRA_* parameters/secrets --- .../action.yml | 6 +++--- ...-for-community-activities-in-this-repo.yml | 5 ++--- ...e-jira-issues-for-community-activities.yml | 20 +++++++++---------- .../post-pull-request-checks-automation.yml | 20 +++++++++---------- .../CreateJiraIssuesForCommunityActivities.md | 20 ++++++++++++++----- .../PostPullRequestChecksAutomation.md | 13 ++++++++---- 6 files changed, 47 insertions(+), 37 deletions(-) diff --git a/.github/actions/create-jira-issues-for-community-activities/action.yml b/.github/actions/create-jira-issues-for-community-activities/action.yml index b9345dbda..1ea921dad 100644 --- a/.github/actions/create-jira-issues-for-community-activities/action.yml +++ b/.github/actions/create-jira-issues-for-community-activities/action.yml @@ -114,10 +114,10 @@ runs: title = '${{ steps.issue-details.outputs.link-title }}' } } - $authorizationBytes = [Text.Encoding]::ASCII.GetBytes('${{ env.JIRA_USER_EMAIL }}:${{ env.JIRA_API_TOKEN }}') + $authorizationBytes = [Text.Encoding]::ASCII.GetBytes('${{ env.JIRA_USER_EMAIL }}:${{ env.JIRA_API_KEY }}') $authorizationBytesBase64 = [Convert]::ToBase64String($authorizationBytes) $requestParameters = @{ - Uri = '${{ env.JIRA_BASE_URL }}/rest/api/3/issue/${{ steps.create-issue.outputs.issue }}/remotelink' + Uri = '${{ env.JIRA_ENDPOINT_URL }}/rest/api/3/issue/${{ steps.create-issue.outputs.issue }}/remotelink' Method = 'POST' ContentType = 'application/json' Headers = @{ @@ -138,5 +138,5 @@ runs: token: ${{ env.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} title: ${{ github.event.issue.title }} (${{ steps.create-issue.outputs.issue }}) - body: "${{ github.event.issue.body }}\n\n[Jira issue](${{ env.JIRA_BASE_URL }}/browse/${{ steps.create-issue.outputs.issue }})" + body: "${{ github.event.issue.body }}\n\n[Jira issue](${{ env.JIRA_ENDPOINT_URL }}/browse/${{ steps.create-issue.outputs.issue }})" update-mode: "replace" diff --git a/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml b/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml index 7a3d1fcff..17d9d5fca 100644 --- a/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml +++ b/.github/workflows/create-jira-issues-for-community-activities-in-this-repo.yml @@ -13,9 +13,8 @@ jobs: name: Create Jira issues for community activities uses: Lombiq/GitHub-Actions/.github/workflows/create-jira-issues-for-community-activities.yml@issue/OSOE-726 secrets: - JIRA_BASE_URL: ${{ secrets.DEFAULT_JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.DEFAULT_JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.DEFAULT_JIRA_API_TOKEN }} + JIRA_ENDPOINT_URL: ${{ secrets.DEFAULT_JIRA_ENDPOINT_URL }} + JIRA_API_KEY: ${{ secrets.DEFAULT_JIRA_API_KEY }} JIRA_PROJECT_KEY: ${{ secrets.DEFAULT_JIRA_PROJECT_KEY }} DISCUSSION_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DEFAULT_DISCUSSION_JIRA_ISSUE_DESCRIPTION }} ISSUE_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DEFAULT_ISSUE_JIRA_ISSUE_DESCRIPTION }} diff --git a/.github/workflows/create-jira-issues-for-community-activities.yml b/.github/workflows/create-jira-issues-for-community-activities.yml index dd020f629..62c4544ca 100644 --- a/.github/workflows/create-jira-issues-for-community-activities.yml +++ b/.github/workflows/create-jira-issues-for-community-activities.yml @@ -4,17 +4,16 @@ on: workflow_call: secrets: # We can't access org secrets here so they need to be passed in. - JIRA_BASE_URL: + JIRA_ENDPOINT_URL: required: true description: > - Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. Note that - it must NOT end with a slash. - JIRA_USER_EMAIL: + Configure as explained under + https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md. + JIRA_API_KEY: required: true - description: Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. - JIRA_API_TOKEN: - required: true - description: Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. + description: > + Configure as explained under + https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md. JIRA_PROJECT_KEY: required: true description: The project key in JIRA, i.e. the prefix of issue keys (the "KEY" part of KEY-123). @@ -58,9 +57,8 @@ jobs: - name: Create Jira issues for community activities uses: Lombiq/GitHub-Actions/.github/actions/create-jira-issues-for-community-activities@issue/OSOE-726 env: - JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + JIRA_ENDPOINT_URL: ${{ secrets.JIRA_ENDPOINT_URL }} + JIRA_API_KEY: ${{ secrets.JIRA_API_KEY }} JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }} DISCUSSION_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DISCUSSION_JIRA_ISSUE_DESCRIPTION }} ISSUE_JIRA_ISSUE_DESCRIPTION: ${{ secrets.ISSUE_JIRA_ISSUE_DESCRIPTION }} diff --git a/.github/workflows/post-pull-request-checks-automation.yml b/.github/workflows/post-pull-request-checks-automation.yml index c6161e09f..32bbf3b8d 100644 --- a/.github/workflows/post-pull-request-checks-automation.yml +++ b/.github/workflows/post-pull-request-checks-automation.yml @@ -17,17 +17,16 @@ on: for info on how to create PATs; you'll need one with the "repo" scope. Check out https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs for instructions on what other tokens you can use. - JIRA_BASE_URL: + JIRA_ENDPOINT_URL: required: true description: > - Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. Note that - it must NOT end with a slash. - JIRA_USER_EMAIL: + Configure as explained under + https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md. + JIRA_API_KEY: required: true - description: Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. - JIRA_API_TOKEN: - required: true - description: Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. + description: > + Configure as explained under + https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md. inputs: merge-method: @@ -83,9 +82,8 @@ jobs: uses: Lombiq/GitHub-Actions/.github/actions/auto-resolve-done-jira-issue@issue/OSOE-726 env: GITHUB_TOKEN: ${{ env.MERGE_TOKEN }} - JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + JIRA_ENDPOINT_URL: ${{ secrets.JIRA_ENDPOINT_URL }} + JIRA_API_KEY: ${{ secrets.JIRA_API_KEY }} - name: Remove Label if: steps.check-steps-should-run.outputs.is-latest != 'false' diff --git a/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md b/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md index d4e73e5f3..189394411 100644 --- a/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md +++ b/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md @@ -2,7 +2,14 @@ Creates Jira issues for community activities happening on GitHub, like issues, discussions, and pull requests being opened. Pull requests are only taken into account if they're not already related to a Jira issue (by starting their title with a Jira issue key). -Set up secrets for the `JIRA_*` parameters as explained [here](https://github.com/marketplace/actions/jira-login#enviroment-variables). You may use secret names without the `DEFAULT_*` prefix, but that's our recommendation for organization-level secrets, so you have defaults but can override them on a per-repository basis. +[Jira API tokens](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/) have the same access as the user account they were created for, and their scope can't be restricted ([nor can there be single-use Jira guest users](https://jira.atlassian.com/browse/JRACLOUD-74242)). Thus you'd normally need to have a separate API user account for each use case (unless you want to open up API access too much). Due to this limitation, we're using the [API Key Manager for Jira extension](https://marketplace.atlassian.com/apps/1228630/api-key-manager-for-jira) to provide scope-limited API access. + +## Prerequisites + +1. Install the [API Key Manager for Jira extension](https://marketplace.atlassian.com/apps/1228630/api-key-manager-for-jira) in your Jira instance. +2. Set up organization or repository secrets for the `JIRA_*` parameters. You may use secret names without the `DEFAULT_*` prefix, but that's our recommendation for organization-level secrets, so you have defaults but can override them on a per-repository basis. + +Set up organization or repository secrets for the issue templates, see below. The secrets with the `*_JIRA_ISSUE_DESCRIPTION` suffix should contain templates for the Jira issues to be created, using the internal markup format of Jira (not Markdown). Example for one for `ISSUE_JIRA_ISSUE_DESCRIPTION`: @@ -15,7 +22,11 @@ h1. Checklist * [Issue completion checklist|https://example.com/checklist] ``` -All three templates are optional and if not provided, defaults will be used. Note that it's important to use the `pull_request_target` trigger instead of `pull_request` because the latter doesn't trigger for pull requests from forks, defeating the whole purpose of this workflow. +All three templates are optional and if not provided, defaults will be used. + +## Setup + +You can use the workflow as demonstrated below. Note that it's important to use the `pull_request_target` trigger instead of `pull_request` because the latter doesn't trigger for pull requests from forks, defeating the whole purpose of this workflow. ```yaml name: Create Jira issues for community activities @@ -33,9 +44,8 @@ jobs: name: Create Jira issues for community activities uses: Lombiq/GitHub-Actions/.github/workflows/create-jira-issues-for-community-activities.yml@dev secrets: - JIRA_BASE_URL: ${{ secrets.DEFAULT_JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.DEFAULT_JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.DEFAULT_JIRA_API_TOKEN }} + JIRA_ENDPOINT_URL: ${{ secrets.DEFAULT_JIRA_ENDPOINT_URL }} + JIRA_API_KEY: ${{ secrets.DEFAULT_JIRA_API_KEY }} JIRA_PROJECT_KEY: ${{ secrets.DEFAULT_JIRA_PROJECT_KEY }} DISCUSSION_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DEFAULT_DISCUSSION_JIRA_ISSUE_DESCRIPTION }} ISSUE_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DEFAULT_ISSUE_JIRA_ISSUE_DESCRIPTION }} diff --git a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md index 376a4bff0..465f9f4ee 100644 --- a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md +++ b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md @@ -5,7 +5,13 @@ Various automation that should be run after all other checks succeeded for a pul - Merges the current pull request if the "merge-and-resolve-jira-issue-if-checks-succeed" or "merge-if-checks-succeed" label is present. With prerequisite jobs you can execute this only if all others jobs have succeeded. Unlike [GitHub's auto-merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request), this works without branch protection rules. - Resolves the Jira issue corresponding to the pull request if the "resolve-jira-issue-if-checks-succeed" or "merge-and-resolve-jira-issue-if-checks-succeed" label is present, or sets the issue to Done if the "done-jira-issue-if-checks-succeed" label is. -See an example of how you can utilize this workflow, together with jobs that do other checks below. For configuring the `JIRA_*` secrets see the [documentation of `create-jira-issues-for-community-activities`](CreateJiraIssuesForCommunityActivities.md), and for details on `MERGE_TOKEN` check out the workflow's inline documentation. +## Prerequisites + +You'll need to configure `JIRA_*` secrets first. See the [documentation of `create-jira-issues-for-community-activities`](CreateJiraIssuesForCommunityActivities.md) for details. + +## Setup + +See an example of how you can utilize this workflow, together with jobs that do other checks below. For details on `MERGE_TOKEN` check out the workflow's inline documentation. ```yaml name: Build and Test @@ -31,9 +37,8 @@ jobs: if: github.event.pull_request != '' uses: Lombiq/GitHub-Actions/.github/workflows/post-pull-request-checks-automation.yml@dev secrets: - JIRA_BASE_URL: ${{ secrets.DEFAULT_JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.DEFAULT_JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.DEFAULT_JIRA_API_TOKEN }} + JIRA_ENDPOINT_URL: ${{ secrets.DEFAULT_JIRA_ENDPOINT_URL }} + JIRA_API_KEY: ${{ secrets.DEFAULT_JIRA_API_KEY }} MERGE_TOKEN: ${{ secrets.DEFAULT_MERGE_TOKEN }} ``` From adcdd05d220f6f0006aae51d489f8a6a14df345b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 00:46:40 +0100 Subject: [PATCH 04/15] Better docs --- .github/workflows/validate-pull-request.yml | 6 +++--- .github/workflows/validate-submodule-pull-request.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validate-pull-request.yml b/.github/workflows/validate-pull-request.yml index ca14a56e4..14c0fbddf 100644 --- a/.github/workflows/validate-pull-request.yml +++ b/.github/workflows/validate-pull-request.yml @@ -2,13 +2,13 @@ name: Validate Pull Request on: workflow_call: + # We can't access org secrets here so they must be passed in. secrets: - # We can't access org secrets here so they must be passed in. JIRA_BASE_URL: required: false description: > - Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. Note that - it must NOT end with a slash. + The URL of your Jira instance, following the https://.atlassian.net pattern. It must NOT end with + a slash. inputs: timeout-minutes: type: number diff --git a/.github/workflows/validate-submodule-pull-request.yml b/.github/workflows/validate-submodule-pull-request.yml index 327f2817b..5c21d1afb 100644 --- a/.github/workflows/validate-submodule-pull-request.yml +++ b/.github/workflows/validate-submodule-pull-request.yml @@ -7,8 +7,8 @@ on: JIRA_BASE_URL: required: false description: > - Configure as explained under https://github.com/marketplace/actions/jira-login#enviroment-variables. Note that - it must NOT end with a slash. + The URL of your Jira instance, following the https://.atlassian.net pattern. It must NOT end with + a slash. inputs: repository: type: string From a61175e06739221500eb57ef8d694f14ac027be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 00:47:49 +0100 Subject: [PATCH 05/15] Docs --- .../workflows/create-jira-issues-for-community-activities.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create-jira-issues-for-community-activities.yml b/.github/workflows/create-jira-issues-for-community-activities.yml index 62c4544ca..f6cfe984e 100644 --- a/.github/workflows/create-jira-issues-for-community-activities.yml +++ b/.github/workflows/create-jira-issues-for-community-activities.yml @@ -8,12 +8,12 @@ on: required: true description: > Configure as explained under - https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md. + https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md. JIRA_API_KEY: required: true description: > Configure as explained under - https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md. + https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md. JIRA_PROJECT_KEY: required: true description: The project key in JIRA, i.e. the prefix of issue keys (the "KEY" part of KEY-123). From 7b09b2858bc12e10fa6fbfbe1ff30fd437ceb8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 01:47:38 +0100 Subject: [PATCH 06/15] Adding missing branch reference --- .github/workflows/validate-this-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-this-pull-request.yml b/.github/workflows/validate-this-pull-request.yml index 60853a4e9..10a4da2f5 100644 --- a/.github/workflows/validate-this-pull-request.yml +++ b/.github/workflows/validate-this-pull-request.yml @@ -7,4 +7,4 @@ on: jobs: validate-pull-request: - uses: Lombiq/GitHub-Actions/.github/workflows/validate-submodule-pull-request.yml@dev + uses: Lombiq/GitHub-Actions/.github/workflows/validate-submodule-pull-request.yml@issue/OSOE-726 From f1d765ae6b9ddfafac4b1573c549f0dac6b32144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 02:26:29 +0100 Subject: [PATCH 07/15] Migrated Automatically Resolve or Done Jira issue to API Key Manager --- .../Initialize-IssueParameters.ps1 | 25 -------- .../Update-JiraIssue.ps1 | 63 +++++++++++++++++++ .../auto-resolve-done-jira-issue/action.yml | 23 +------ .../CreateJiraIssuesForCommunityActivities.md | 11 +++- .../PostPullRequestChecksAutomation.md | 7 ++- 5 files changed, 79 insertions(+), 50 deletions(-) delete mode 100644 .github/actions/auto-resolve-done-jira-issue/Initialize-IssueParameters.ps1 create mode 100644 .github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 diff --git a/.github/actions/auto-resolve-done-jira-issue/Initialize-IssueParameters.ps1 b/.github/actions/auto-resolve-done-jira-issue/Initialize-IssueParameters.ps1 deleted file mode 100644 index feb36c0cc..000000000 --- a/.github/actions/auto-resolve-done-jira-issue/Initialize-IssueParameters.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -param($Repository, $PullRequestNumber, $IsDone, $IsResolve) - -# We need to fetch the PR details using the CLI (see https://cli.github.com/manual/gh_pr_view) as opposed to just using -# the context, because the title may have changed (by the user or the add-jira-issue-code-to-pull-request action) after -# the start of the run and that wouldn't be present in it. -$title = gh pr view $PullRequestNumber --repo $Repository --json title --template '{{.title}}' -$issueKey = Get-JiraIssueKeyFromPullRequestTitle $title - -Set-GitHubOutput 'key' $issueKey - -if ($IsDone) -{ - $transition = 'Done' -} -elseif ($IsResolve) -{ - $transition = 'Resolve' -} -else -{ - $transition = '' -} - -Set-GitHubOutput 'transition' $transition -Set-GitHubOutput 'can-transition' (-not [string]::IsNullOrEmpty($issueKey) -and $transition -ne '') diff --git a/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 b/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 new file mode 100644 index 000000000..ee963f016 --- /dev/null +++ b/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 @@ -0,0 +1,63 @@ +param($Repository, $PullRequestNumber, $IsDone, $IsResolve) + +# We need to fetch the PR details using the CLI (see https://cli.github.com/manual/gh_pr_view) as opposed to just using +# the context, because the title may have changed (by the user or the add-jira-issue-code-to-pull-request action) after +# the start of the run and that wouldn't be present in it. +$title = gh pr view $PullRequestNumber --repo $Repository --json title --template '{{.title}}' +$issueKey = Get-JiraIssueKeyFromPullRequestTitle $title + +$transition = $IsDone ? 'Done' : ($IsResolve ? 'Resolve' : $null) + +if ($transition -eq $null) +{ + Write-Error 'Unknown Jira issue transition was selected.' + exit +} + +$headers = @{ + 'apikey' = $Env:JIRA_API_KEY + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' +} + +$body = @{ + options = @{ + method = 'GET' + headers = @{ + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' + } + } + url = "/rest/api/3/issue/$issueKey/transitions" +} | ConvertTo-Json + +$response = Invoke-RestMethod -Uri $Env:JIRA_ENDPOINT_URL -Method Get -Headers $headers -Body $body + +$availableTransition = $response | Select-Object -ExpandProperty transitions | Where-Object { $_.name -eq $transition } + +if ($availableTransition -ne $null) +{ + Write-Host "Transition exists. $($availableTransition.id)" + + $body = @{ + options = @{ + method = 'POST' + headers = @{ + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' + } + body = @{ + transition = @{ + id = $availableTransition.id + } + } + } + url = "/rest/api/3/issue/$issueKey/transitions" + } | ConvertTo-Json -Depth 3 + + $response = Invoke-RestMethod -Uri $Env:JIRA_ENDPOINT_URL -Method Post -Headers $headers -Body $body +} +else +{ + Write-Warning "The ""$transition"" transition is not available for the issue." +} diff --git a/.github/actions/auto-resolve-done-jira-issue/action.yml b/.github/actions/auto-resolve-done-jira-issue/action.yml index c8561afad..68f485fa0 100644 --- a/.github/actions/auto-resolve-done-jira-issue/action.yml +++ b/.github/actions/auto-resolve-done-jira-issue/action.yml @@ -28,8 +28,7 @@ runs: label1: "resolve-jira-issue-if-checks-succeed" label2: "merge-and-resolve-jira-issue-if-checks-succeed" - - name: Initialize Jira Issue Parameters - id: initialize-jira-issue-parameters + - name: Transition Jira Issue if: steps.check-done.outputs.contains-label == 'true' || steps.check-resolve.outputs.contains-label == 'true' shell: pwsh run: | @@ -39,27 +38,9 @@ runs: IsDone = '${{ steps.check-done.outputs.contains-label }}' -eq 'True' IsResolve = '${{ steps.check-resolve.outputs.contains-label }}' -eq 'True' } - Initialize-IssueParameters @parameters - - - name: Login to Jira - if: steps.initialize-jira-issue-parameters.outputs.can-transition == 'true' - # v3 - uses: atlassian/gajira-login@ca13f8850ea309cf44a6e4e0c49d9aa48ac3ca4c - env: - JIRA_BASE_URL: ${{ env.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ env.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ env.JIRA_API_TOKEN }} - - - name: Transition Jira Issue - if: steps.initialize-jira-issue-parameters.outputs.can-transition == 'true' - # v3 - uses: atlassian/gajira-transition@4749176faf14633954d72af7a44d7f2af01cc92b - with: - issue: ${{ steps.initialize-jira-issue-parameters.outputs.key }} - transition: ${{ steps.initialize-jira-issue-parameters.outputs.transition }} + Update-JiraIssue @parameters - name: Remove Label - if: steps.initialize-jira-issue-parameters.outputs.can-transition == 'true' # v2.0.0 uses: buildsville/add-remove-label@eeae411a9be2e173f2420e1644514edbecc4e835 with: diff --git a/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md b/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md index 189394411..c15b6e71a 100644 --- a/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md +++ b/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md @@ -7,9 +7,14 @@ Creates Jira issues for community activities happening on GitHub, like issues, d ## Prerequisites 1. Install the [API Key Manager for Jira extension](https://marketplace.atlassian.com/apps/1228630/api-key-manager-for-jira) in your Jira instance. -2. Set up organization or repository secrets for the `JIRA_*` parameters. You may use secret names without the `DEFAULT_*` prefix, but that's our recommendation for organization-level secrets, so you have defaults but can override them on a per-repository basis. - -Set up organization or repository secrets for the issue templates, see below. +2. Set up organization or repository secrets for the `JIRA_*` parameters. You may use secret names without the `DEFAULT_*` prefix, but that's our recommendation for organization-level secrets, so you have defaults but can override them on a per-repository basis. For repository secrets, names without this prefix is recommended. + - `DEFAULT_JIRA_ENDPOINT_URL`: The Endpoint URL indicated under the API Key Manager settings in Jira in the Apps menu. + - `DEFAULT_JIRA_API_KEY`: Under the API Key Manager settings in Jira in the Apps menu, create an API key with the following settings + - Valid until: Unless you want to rotate the keys manually, remove the expiration. + - Description: "Create Jira issues for community activities for " (or what you prefer). + - Allowed methods: POST. + - Allowed endpoints: "/rest/api/3/issue/-". +3. Set up organization or repository secrets for the issue templates, see below. The secrets with the `*_JIRA_ISSUE_DESCRIPTION` suffix should contain templates for the Jira issues to be created, using the internal markup format of Jira (not Markdown). Example for one for `ISSUE_JIRA_ISSUE_DESCRIPTION`: diff --git a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md index 465f9f4ee..97f6e6c10 100644 --- a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md +++ b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md @@ -7,7 +7,12 @@ Various automation that should be run after all other checks succeeded for a pul ## Prerequisites -You'll need to configure `JIRA_*` secrets first. See the [documentation of `create-jira-issues-for-community-activities`](CreateJiraIssuesForCommunityActivities.md) for details. +You'll need to configure `JIRA_*` secrets first. See the [documentation of `create-jira-issues-for-community-activities`](CreateJiraIssuesForCommunityActivities.md) for details. The only difference is how you set up the `DEFAULT_JIRA_API_KEY`; use the following settings for the key: + +- Valid until: Unless you want to rotate the keys manually, remove the expiration. +- Description: "Post-pull request checks automation for " (or what you prefer). +- Allowed methods: GET, POST. +- Allowed endpoints: "/rest/api/3/issue/-". ## Setup From a09dfea8fa85987c335a7fcf9eab9972ec2c770e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 02:31:38 +0100 Subject: [PATCH 08/15] Adding missing label --- .github/actions/auto-resolve-done-jira-issue/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/auto-resolve-done-jira-issue/action.yml b/.github/actions/auto-resolve-done-jira-issue/action.yml index 68f485fa0..6229fada5 100644 --- a/.github/actions/auto-resolve-done-jira-issue/action.yml +++ b/.github/actions/auto-resolve-done-jira-issue/action.yml @@ -45,5 +45,5 @@ runs: uses: buildsville/add-remove-label@eeae411a9be2e173f2420e1644514edbecc4e835 with: token: ${{ env.GITHUB_TOKEN }} - labels: resolve-jira-issue-if-checks-succeed, done-jira-issue-if-checks-succeed + labels: merge-and-resolve-jira-issue-if-checks-succeed, resolve-jira-issue-if-checks-succeed, done-jira-issue-if-checks-succeed type: remove From 87c51f205d20718ac5cc14b6cef978e23539939c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 18:21:11 +0100 Subject: [PATCH 09/15] Code styling --- .../actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 b/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 index ee963f016..332584967 100644 --- a/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 +++ b/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 @@ -8,7 +8,7 @@ $issueKey = Get-JiraIssueKeyFromPullRequestTitle $title $transition = $IsDone ? 'Done' : ($IsResolve ? 'Resolve' : $null) -if ($transition -eq $null) +if ($null -eq $transition) { Write-Error 'Unknown Jira issue transition was selected.' exit @@ -35,7 +35,7 @@ $response = Invoke-RestMethod -Uri $Env:JIRA_ENDPOINT_URL -Method Get -Headers $ $availableTransition = $response | Select-Object -ExpandProperty transitions | Where-Object { $_.name -eq $transition } -if ($availableTransition -ne $null) +if ($null -ne $availableTransition) { Write-Host "Transition exists. $($availableTransition.id)" From fefb61be3f83d9c98c0ec04d86f94a48bcdca8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 19:32:17 +0100 Subject: [PATCH 10/15] Temporary dump context --- ...ate-jira-issues-for-community-activities.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/create-jira-issues-for-community-activities.yml b/.github/workflows/create-jira-issues-for-community-activities.yml index f6cfe984e..cee66ea82 100644 --- a/.github/workflows/create-jira-issues-for-community-activities.yml +++ b/.github/workflows/create-jira-issues-for-community-activities.yml @@ -54,16 +54,7 @@ jobs: runs-on: ubuntu-22.04 timeout-minutes: ${{ inputs.timeout-minutes }} steps: - - name: Create Jira issues for community activities - uses: Lombiq/GitHub-Actions/.github/actions/create-jira-issues-for-community-activities@issue/OSOE-726 - env: - JIRA_ENDPOINT_URL: ${{ secrets.JIRA_ENDPOINT_URL }} - JIRA_API_KEY: ${{ secrets.JIRA_API_KEY }} - JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }} - DISCUSSION_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DISCUSSION_JIRA_ISSUE_DESCRIPTION }} - ISSUE_JIRA_ISSUE_DESCRIPTION: ${{ secrets.ISSUE_JIRA_ISSUE_DESCRIPTION }} - PULL_REQUEST_JIRA_ISSUE_DESCRIPTION: ${{ secrets.PULL_REQUEST_JIRA_ISSUE_DESCRIPTION }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - issue-component: ${{ inputs.issue-component }} - suffix-issue-titles: ${{ inputs.suffix-issue-titles }} + - env: + GITHUB_CONTEXT: ${{ toJSON(github) }} + shell: pwsh + run: Write-Output $Env:GITHUB_CONTEXT \ No newline at end of file From 442ccc46aecf054d9e53a0a2977b66ff570d5050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 20:06:05 +0100 Subject: [PATCH 11/15] Revert "Temporary dump context" This reverts commit fefb61be3f83d9c98c0ec04d86f94a48bcdca8f4. --- ...ate-jira-issues-for-community-activities.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/create-jira-issues-for-community-activities.yml b/.github/workflows/create-jira-issues-for-community-activities.yml index cee66ea82..f6cfe984e 100644 --- a/.github/workflows/create-jira-issues-for-community-activities.yml +++ b/.github/workflows/create-jira-issues-for-community-activities.yml @@ -54,7 +54,16 @@ jobs: runs-on: ubuntu-22.04 timeout-minutes: ${{ inputs.timeout-minutes }} steps: - - env: - GITHUB_CONTEXT: ${{ toJSON(github) }} - shell: pwsh - run: Write-Output $Env:GITHUB_CONTEXT \ No newline at end of file + - name: Create Jira issues for community activities + uses: Lombiq/GitHub-Actions/.github/actions/create-jira-issues-for-community-activities@issue/OSOE-726 + env: + JIRA_ENDPOINT_URL: ${{ secrets.JIRA_ENDPOINT_URL }} + JIRA_API_KEY: ${{ secrets.JIRA_API_KEY }} + JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }} + DISCUSSION_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DISCUSSION_JIRA_ISSUE_DESCRIPTION }} + ISSUE_JIRA_ISSUE_DESCRIPTION: ${{ secrets.ISSUE_JIRA_ISSUE_DESCRIPTION }} + PULL_REQUEST_JIRA_ISSUE_DESCRIPTION: ${{ secrets.PULL_REQUEST_JIRA_ISSUE_DESCRIPTION }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + issue-component: ${{ inputs.issue-component }} + suffix-issue-titles: ${{ inputs.suffix-issue-titles }} From 8a9237074ec4e29fc8fa5a83dcf2a8affb188331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 20:06:32 +0100 Subject: [PATCH 12/15] Not using not recommended Write-Host --- .../actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 b/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 index 332584967..3d03e696b 100644 --- a/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 +++ b/.github/actions/auto-resolve-done-jira-issue/Update-JiraIssue.ps1 @@ -37,7 +37,7 @@ $availableTransition = $response | Select-Object -ExpandProperty transitions | W if ($null -ne $availableTransition) { - Write-Host "Transition exists. $($availableTransition.id)" + Write-Output "Transition exists. $($availableTransition.id)" $body = @{ options = @{ From 93b5d272dcd1430f857e2f834534bcaf8458368d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 22:54:32 +0100 Subject: [PATCH 13/15] Migrating "Create Jira issues for community activities" too --- .../Add-JiraIssue.ps1 | 115 ++++++++++++++++++ .../Initialize-IssueDetails.ps1 | 16 +-- .../action.yml | 87 +++---------- .../CreateJiraIssuesForCommunityActivities.md | 6 +- .../PostPullRequestChecksAutomation.md | 4 +- 5 files changed, 148 insertions(+), 80 deletions(-) create mode 100644 .github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 diff --git a/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 b/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 new file mode 100644 index 000000000..2c8ee3b41 --- /dev/null +++ b/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 @@ -0,0 +1,115 @@ +param +( + $Summary, + $Description, + $Type, + $IssueComponent, + $LinkUrl, + $LinkTitle +) + +$headers = @{ + 'apikey' = $Env:JIRA_API_KEY + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' +} + +function CreateIssue { + $body = @{ + options = @{ + method = 'POST' + headers = @{ + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' + } + body = @{ + fields = @{ + project = @{ + key = $Env:JIRA_PROJECT_KEY + } + summary = $Summary + description = @{ + type = 'doc' + version = 1 + content = @( + @{ + type = 'paragraph' + content = @( + @{ + type = 'text' + text = $Description + } + ) + } + ) + } + issuetype = @{ + name = $Type + } + labels = @('created-from-github') + } + } + } + url = "/rest/api/3/issue" + } + + if (-not [string]::IsNullOrWhiteSpace($IssueComponent)) { + $body.options.body.fields += @{ + components = @(@{ + name = $IssueComponent + }) + } + } + + $body = $body | ConvertTo-Json -Depth 9 + + $response = Invoke-RestMethod -Uri $Env:JIRA_ENDPOINT_URL -Method Post -Headers $headers -Body $body + Write-Information "Jira issue created with the key $($response.key)." -InformationAction Continue + $response.key +} + +function AddLink { + param($issueKey) + + $body = @{ + options = @{ + method = 'POST' + headers = @{ + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' + } + body = @{ + object = @{ + url = $LinkUrl + title = $LinkTitle + } + } + } + url = "/rest/api/3/issue/$issueKey/remotelink" + } | ConvertTo-Json -Depth 3 + + Invoke-RestMethod -Uri $Env:JIRA_ENDPOINT_URL -Method Post -Headers $headers -Body $body +} + +function GetIssueUrl { + param($issueKey) + + $body = @{ + options = @{ + method = 'GET' + headers = @{ + 'Content-Type' = 'application/json' + 'Accept' = 'application/json' + } + } + url = "/rest/api/3/serverInfo" + } | ConvertTo-Json + + $response = Invoke-RestMethod -Uri $Env:JIRA_ENDPOINT_URL -Method Get -Headers $headers -Body $body + + "$($response.baseUrl)/browse/$issueKey" +} + +$issueKey = CreateIssue +AddLink $issueKey +Set-GitHubOutput 'issue-url' (GetIssueUrl $issueKey) diff --git a/.github/actions/create-jira-issues-for-community-activities/Initialize-IssueDetails.ps1 b/.github/actions/create-jira-issues-for-community-activities/Initialize-IssueDetails.ps1 index df797f65f..658122f4a 100644 --- a/.github/actions/create-jira-issues-for-community-activities/Initialize-IssueDetails.ps1 +++ b/.github/actions/create-jira-issues-for-community-activities/Initialize-IssueDetails.ps1 @@ -5,7 +5,7 @@ param $SuffixIssueTitles, $DiscussionJiraIssueDescription, $IssueJiraIssueDescription, - $PullReqestJiraIssueDescription + $PullRequestJiraIssueDescription ) $context = [string]::IsNullOrEmpty($IssueComponent) ? $GitHub.repository : $IssueComponent @@ -47,7 +47,7 @@ switch ($GitHub.event_name) 'pull_request_target' { $summary = "Review `"$($GitHub.event.pull_request.title)`"$titleSuffix" - $description = $PullReqestJiraIssueDescription + $description = $PullRequestJiraIssueDescription $linkUrl = $GitHub.event.pull_request.html_url $linkTitle = 'GitHub pull request' } @@ -67,8 +67,10 @@ if ($null -eq $type) $type = 'Task' } -Set-GitHubOutput 'summary' $summary -Set-GitHubOutput 'json-description' $($description | ConvertTo-Json) -Set-GitHubOutput 'type' $type -Set-GitHubOutput 'link-url' $linkUrl -Set-GitHubOutput 'link-title' $linkTitle +[PSCustomObject]@{ + Summary = $summary + Description = $description + Type = $type + LinkUrl = $linkUrl + LinkTitle = $linkTitle +} diff --git a/.github/actions/create-jira-issues-for-community-activities/action.yml b/.github/actions/create-jira-issues-for-community-activities/action.yml index 1ea921dad..13a48a25c 100644 --- a/.github/actions/create-jira-issues-for-community-activities/action.yml +++ b/.github/actions/create-jira-issues-for-community-activities/action.yml @@ -43,23 +43,9 @@ runs: Set-GitHubOutput "is-issue-pr" $output - - name: Login to Jira - if: steps.issue-related-pr.outputs.is-issue-pr == 'False' - # v3 - uses: atlassian/gajira-login@ca13f8850ea309cf44a6e4e0c49d9aa48ac3ca4c - env: - JIRA_BASE_URL: ${{ env.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ env.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ env.JIRA_API_TOKEN }} - - - name: Initialize Jira Issue Templates - if: steps.issue-related-pr.outputs.is-issue-pr == 'False' - shell: pwsh - run: Initialize-IssueTemplates - - - name: Initialize Jira Issue Details + - name: Create Jira Issue if: steps.issue-related-pr.outputs.is-issue-pr == 'False' - id: issue-details + id: create-issue env: # Necessary to pass this via an environment variable, because when assigned directly to a variable in the # script, it can cause escaping issues with backtick characters (like a "`ulong..." causing "The Unicode escape @@ -72,62 +58,27 @@ runs: $templates = Initialize-IssueTemplates - Initialize-IssueDetails $github ` - "${{ inputs.issue-component }}" ` - $([System.Convert]::ToBoolean("${{ inputs.suffix-issue-titles }}")) ` - $templates["DISCUSSION_JIRA_ISSUE_DESCRIPTION"] ` - $templates["ISSUE_JIRA_ISSUE_DESCRIPTION"] ` - $templates["PULL_REQUEST_JIRA_ISSUE_DESCRIPTION"] - - $fields = @" - {"labels": ["created-from-github"] - "@ - - if ("${{ inputs.issue-component }}" -ne "") - { - $fields += ', "components": [{"name": "${{ inputs.issue-component }}"}]' + $params = @{ + GitHub = $github + IssueComponent = '${{ inputs.issue-component }}' + SuffixIssueTitles = [System.Convert]::ToBoolean('${{ inputs.suffix-issue-titles }}') + DiscussionJiraIssueDescription = $templates['DISCUSSION_JIRA_ISSUE_DESCRIPTION'] + IssueJiraIssueDescription = $templates['ISSUE_JIRA_ISSUE_DESCRIPTION'] + PullRequestJiraIssueDescription = $templates['PULL_REQUEST_JIRA_ISSUE_DESCRIPTION'] } - $fields += '}' + $issueDetails = Initialize-IssueDetails @params - Set-GitHubOutput "fields" $fields - - - name: Create Jira Issue - if: steps.issue-related-pr.outputs.is-issue-pr == 'False' - id: create-issue - # v3 - uses: atlassian/gajira-create@1ff0b6bd115a780592b47bfbb63fc4629132e6ec - with: - project: ${{ env.JIRA_PROJECT_KEY }} - issuetype: ${{ steps.issue-details.outputs.type }} - summary: ${{ steps.issue-details.outputs.summary }} - description: ${{ fromJSON(steps.issue-details.outputs.json-description) }} - fields: ${{ steps.issue-details.outputs.fields }} - - - name: Add Remote Link to Jira Issue - if: steps.issue-related-pr.outputs.is-issue-pr == 'False' - shell: pwsh - run: | - $linkProperties = @{ - object = @{ - url = '${{ steps.issue-details.outputs.link-url }}' - title = '${{ steps.issue-details.outputs.link-title }}' - } - } - $authorizationBytes = [Text.Encoding]::ASCII.GetBytes('${{ env.JIRA_USER_EMAIL }}:${{ env.JIRA_API_KEY }}') - $authorizationBytesBase64 = [Convert]::ToBase64String($authorizationBytes) - $requestParameters = @{ - Uri = '${{ env.JIRA_ENDPOINT_URL }}/rest/api/3/issue/${{ steps.create-issue.outputs.issue }}/remotelink' - Method = 'POST' - ContentType = 'application/json' - Headers = @{ - Accept = 'application/json' - Authorization = "Basic $authorizationBytesBase64" - } - Body = ConvertTo-Json($linkProperties) + $params = @{ + Summary = $issueDetails.Summary + Description = $issueDetails.Description + Type = $issueDetails.Type + IssueComponent = '${{ inputs.issue-component }}' + LinkUrl = $issueDetails.LinkUrl + LinkTitle = $issueDetails.LinkTitle } - Invoke-WebRequest @requestParameters + .\Add-JiraIssue @params - name: Update GitHub Issue if: steps.issue-related-pr.outputs.is-issue-pr == 'False' && github.event.issue @@ -138,5 +89,5 @@ runs: token: ${{ env.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} title: ${{ github.event.issue.title }} (${{ steps.create-issue.outputs.issue }}) - body: "${{ github.event.issue.body }}\n\n[Jira issue](${{ env.JIRA_ENDPOINT_URL }}/browse/${{ steps.create-issue.outputs.issue }})" + body: "${{ github.event.issue.body }}\n\n[Jira issue](${{ steps.create-issue.outputs.issue-url }})" update-mode: "replace" diff --git a/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md b/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md index c15b6e71a..2a166295d 100644 --- a/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md +++ b/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md @@ -11,9 +11,9 @@ Creates Jira issues for community activities happening on GitHub, like issues, d - `DEFAULT_JIRA_ENDPOINT_URL`: The Endpoint URL indicated under the API Key Manager settings in Jira in the Apps menu. - `DEFAULT_JIRA_API_KEY`: Under the API Key Manager settings in Jira in the Apps menu, create an API key with the following settings - Valid until: Unless you want to rotate the keys manually, remove the expiration. - - Description: "Create Jira issues for community activities for " (or what you prefer). - - Allowed methods: POST. - - Allowed endpoints: "/rest/api/3/issue/-". + - Description: "Create Jira issues for community activities for \" (or what you prefer). + - Allowed methods: GET, POST. + - Allowed endpoints: "/rest/api/3/issue", "/rest/api/3/serverInfo". 3. Set up organization or repository secrets for the issue templates, see below. The secrets with the `*_JIRA_ISSUE_DESCRIPTION` suffix should contain templates for the Jira issues to be created, using the internal markup format of Jira (not Markdown). Example for one for `ISSUE_JIRA_ISSUE_DESCRIPTION`: diff --git a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md index 97f6e6c10..9dfac13fa 100644 --- a/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md +++ b/Docs/Workflows/Productivity/PostPullRequestChecksAutomation.md @@ -10,9 +10,9 @@ Various automation that should be run after all other checks succeeded for a pul You'll need to configure `JIRA_*` secrets first. See the [documentation of `create-jira-issues-for-community-activities`](CreateJiraIssuesForCommunityActivities.md) for details. The only difference is how you set up the `DEFAULT_JIRA_API_KEY`; use the following settings for the key: - Valid until: Unless you want to rotate the keys manually, remove the expiration. -- Description: "Post-pull request checks automation for " (or what you prefer). +- Description: "Post-pull request checks automation for \" (or what you prefer). - Allowed methods: GET, POST. -- Allowed endpoints: "/rest/api/3/issue/-". +- Allowed endpoints: "/rest/api/3/issue/\-". ## Setup From d26a7f89aeb0eb4ec2ed7ed7d14343712cf2e26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 22:55:36 +0100 Subject: [PATCH 14/15] Script path fix --- .../create-jira-issues-for-community-activities/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/create-jira-issues-for-community-activities/action.yml b/.github/actions/create-jira-issues-for-community-activities/action.yml index 13a48a25c..315aa6c4e 100644 --- a/.github/actions/create-jira-issues-for-community-activities/action.yml +++ b/.github/actions/create-jira-issues-for-community-activities/action.yml @@ -78,7 +78,7 @@ runs: LinkTitle = $issueDetails.LinkTitle } - .\Add-JiraIssue @params + Add-JiraIssue @params - name: Update GitHub Issue if: steps.issue-related-pr.outputs.is-issue-pr == 'False' && github.event.issue From b3ec0ba9935205fca286fcb3c3418e8a1bf7dc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 16 Dec 2023 23:01:54 +0100 Subject: [PATCH 15/15] Fixing that the issue key wasn't added to the GH issue's title --- .../Add-JiraIssue.ps1 | 1 + .../create-jira-issues-for-community-activities/action.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 b/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 index 2c8ee3b41..9c693bfa6 100644 --- a/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 +++ b/.github/actions/create-jira-issues-for-community-activities/Add-JiraIssue.ps1 @@ -112,4 +112,5 @@ function GetIssueUrl { $issueKey = CreateIssue AddLink $issueKey +Set-GitHubOutput 'issue-key' $issueKey Set-GitHubOutput 'issue-url' (GetIssueUrl $issueKey) diff --git a/.github/actions/create-jira-issues-for-community-activities/action.yml b/.github/actions/create-jira-issues-for-community-activities/action.yml index 315aa6c4e..571f7d3e5 100644 --- a/.github/actions/create-jira-issues-for-community-activities/action.yml +++ b/.github/actions/create-jira-issues-for-community-activities/action.yml @@ -88,6 +88,6 @@ runs: actions: "update-issue" token: ${{ env.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} - title: ${{ github.event.issue.title }} (${{ steps.create-issue.outputs.issue }}) + title: ${{ github.event.issue.title }} (${{ steps.create-issue.outputs.issue-key }}) body: "${{ github.event.issue.body }}\n\n[Jira issue](${{ steps.create-issue.outputs.issue-url }})" update-mode: "replace"