-
Notifications
You must be signed in to change notification settings - Fork 69
108 lines (102 loc) · 4.73 KB
/
quick_pr.yml
File metadata and controls
108 lines (102 loc) · 4.73 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: "Create an issue in the repository for a PR that does not have one yet"
# This file is part of t8code.
# t8code is a C library to manage a collection (a forest) of multiple
# connected adaptive space-trees of general element types in parallel.
#
# Copyright (C) 2025 the developers
#
# t8code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# t8code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with t8code; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
on:
workflow_call:
inputs:
DEFAULT_PROJECT:
type: string
description: 'The default project to use for the issue'
required: true
default: ''
secrets:
PAT:
required: true
outputs:
ISSUE_NUMBER:
description: 'The number of the issue that was created'
value: ${{ jobs.create_issue.outputs.ISSUE_NUMBER }}
jobs:
create_issue:
runs-on: ubuntu-latest
outputs:
ISSUE_NUMBER: ${{ steps.create_issue_and_output_number.outputs.ISSUE_NUMBER }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: "Set up environment"
run: echo "GH_TOKEN=${{ secrets.PAT }}" >> $GITHUB_ENV
- name: "Create Issue"
id: create_issue_and_output_number
run: |
# Get the title of the triggering PR
TITLE="${{ github.event.pull_request.title }}"
AUTHOR="${{ github.event.pull_request.user.login }}"
ISSUE_BODY=""
DRAFT=$([[ "${{ github.event.pull_request.draft }}" == "true" ]] && echo "true" || echo "false")
if [[ "$DRAFT" == "true" ]]; then
ISSUE_BODY="This Issue was created because the draft PR did not reference an Issue. Please @${AUTHOR} describe the Issue that you are solving."
else
ISSUE_BODY="This Issue was created because the PR did not reference an Issue."
fi
echo "TITLE=$TITLE"
echo "AUTHOR=$AUTHOR"
# Create the new issue. Use the DEFAULT_PROJECT to directly add it to the project.
# Letting GH add the Issue to the project by automatization can lead to a delay,
# and the following worfkflows will try to move a card that doesn't exist yet.
# Only assign the issue if the author is not a bot
if [[ "$AUTHOR" == *"[bot]"* ]]; then
new_issue_url=$(gh issue create \
--title "$TITLE" \
--body "$ISSUE_BODY" \
--project "${{ inputs.DEFAULT_PROJECT }}"
)
else
new_issue_url=$(gh issue create \
--title "$TITLE" \
--assignee "$AUTHOR" \
--body "$ISSUE_BODY" \
--project "${{ inputs.DEFAULT_PROJECT }}"
)
fi
echo "new_issue_url=$new_issue_url"
# Extract the issue number from the URL.
# The URL is in the format https://github.com/orga-name/repo-name/issues/issues_number
ISSUE_NUMBER=$(echo "$new_issue_url" | awk -F'/' '{print $NF}')
echo "ISSUE_NUMBER=$ISSUE_NUMBER"
echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
- name: "Link Issue to PR"
id: link_issue
run: |
# Add "Closes #ISSUE_NUMBER" to the PR body
ISSUE_NUMBER="${{ steps.create_issue_and_output_number.outputs.ISSUE_NUMBER }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
echo "ISSUE_NUMBER=$ISSUE_NUMBER"
echo "PR_NUMBER=$PR_NUMBER"
# Get the PR body
pr_body=$(jq -r '.pull_request.body // ""' < $GITHUB_EVENT_PATH)
echo "pr_body=$pr_body"
# Add the issue number to the PR body
# Add "Closes #ISSUE_NUMBER" to the top of the PR body
new_pr_body=$(printf "Closes #%s\n\n%s" "$ISSUE_NUMBER" "$pr_body")
echo "new_pr_body=$new_pr_body"
# Update the PR body
gh pr edit "$PR_NUMBER" --body "$new_pr_body"