92 lines (91 loc) · 2.89 KB
/
link-to-redmine.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Links an existing issue in Redmine to the specified pull request.
#
# Example Usage:
# --------------
# name: My favorite workflow
# on:
# pull_request:
# types: [opened]
# jobs:
# extractnum:
# runs-on: ubuntu-latest
# outputs:
# issue: ${{ steps.extract.outputs.replaced }}
# steps:
# - id: extract
# uses: frabert/replace-string-action@v2
# with:
# pattern: "^(task|issue|bug)(\\d+)-.*$"
# flags: "i"
# string: "${{ github.head_ref }}"
# replace-with: "$2"
#
# link-to-redmine:
# needs: extractnum
# if: ${{ needs.extractnum.outputs.issue != github.head_ref }}
# permissions:
# contents: read
# pull-requests: write
# uses: pangaeatech/.github/.github/workflows/link-to-redmine.yml@main
# with:
# pr_num: ${{github.event.pull_request.number}}
# pr_url: ${{github.event.pull_request.html_url}}
# rm_url: "https://redmine.mycompany.com/"
# rm_issue: ${{ needs.extractnum.outputs.issue }}
# rm_field_id: 11
# secrets:
# rm_key: ${{ secrets.REDMINE_API_KEY }}
name: Link To Redmine
on:
workflow_call:
inputs:
pr_num:
# The Pull Request Number
required: true
type: string
pr_url:
# The Pull Request URL
required: true
type: string
rm_url:
# The Redmine URL
required: true
type: string
rm_issue:
# The redmine issue to link to
required: true
type: string
rm_field_id:
# The redmine custom field ID to store the PR number in
required: true
type: number
secrets:
rm_key:
# The REST API Key of the redmine user to post as
# NOTE: This user MUST have permission to "Edit issues" and also
# to "Add notes" on the project specified by rm_project_id
required: true
jobs:
annotate:
runs-on: ubuntu-latest
steps:
- name: Link task to redmine
run: |
sudo apt-get install -y jq curl
BODY=$(echo "Linked to \"Pull Request $PR_NUM\":$PR_URL")
jq --null-input \
--arg key "$RM_KEY" \
--arg body "$BODY" \
--arg prnum "$PR_NUM" \
--arg fld "$RM_FIELD_ID" \
'{key:$key,issue:{notes:$body,custom_fields:[{value:$prnum,id:$fld}]}}' > body.json
curl -s -X PUT -H "Content-Type: application/json" -d "@body.json" "${RM_URL}/issues/${RM_ISSUE}.json"
gh pr comment "$PR_URL" -b "Linked to [Redmine Task ${RM_ISSUE}]($RM_URL/issues/${RM_ISSUE})";
env:
PR_URL: ${{ inputs.pr_url }}
PR_NUM: ${{ inputs.pr_num }}
RM_ISSUE: ${{ inputs.rm_issue }}
RM_FIELD_ID: ${{ inputs.rm_field_id }}
RM_URL: ${{ inputs.rm_url }}
RM_KEY: ${{ secrets.rm_key }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}