-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 43d3df4
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ubuntu:latest | ||
|
||
COPY get-closing-labels.sh entrypoint.sh / | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
curl \ | ||
jq \ | ||
git \ | ||
gh \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Sync Closing Labels | ||
|
||
GitHub action to add closing labels to a pull request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: "Sync Closing Labels" | ||
description: 'A GitHub action to sync closing labels for a pull request' | ||
inputs: | ||
exclude: | ||
description: "A list of comma separate labels to not add" | ||
required: false | ||
default: "" | ||
respect-unlabeled: | ||
description: "If true, removing label will keep the label removed" | ||
required: false | ||
default: "true" | ||
owner: | ||
description: "The owner of the repository" | ||
required: true | ||
default: ${{ github.repository_owner }} | ||
repo: | ||
description: "The repository name" | ||
required: true | ||
default: ${{ github.event.repository.name }} | ||
pr_number: | ||
description: "The pull request number" | ||
required: true | ||
default: ${{ github.event.number }} | ||
runs: | ||
using: 'docker' | ||
image: 'ubuntu:latest' | ||
entrypoint: '/entrypoint.sh' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh -l | ||
|
||
./get-closing-labels.sh -o $INPUT_OWNER -n $INPUT_NAME -p $INPUT_PR_NUMBER | jq \ | ||
--arg ignore "$INPUT_IGNORE" \ | ||
--arg respect_unlabeled "$INPUT_RESPECT_UNLABELED" \ | ||
'def split_ignore: if $ignore == "" then [] else $ignore | split(",") end; | ||
.closing as $closing | | ||
.removed as $removed | | ||
split_ignore as $ignore_split | | ||
{ | ||
closing: $closing, | ||
removed: $removed, | ||
ignore_split: $ignore_split, | ||
result: ( | ||
if $respect_unlabeled == "true" | ||
then $closing - $removed | ||
else $closing end | ||
- $ignore_split | ||
) | ||
} | .result | join(",")' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
# Function to display usage | ||
usage() { | ||
echo "Usage: $0 -o owner -n name -p pr_number" | ||
exit | ||
} | ||
|
||
# Parse command-line arguments | ||
while getopts ":o:n:p:" opt; do | ||
case $opt in | ||
o) owner="$OPTARG" | ||
;; | ||
n) name="$OPTARG" | ||
;; | ||
p) pr_number="$OPTARG" | ||
;; | ||
\?) echo "Invalid option -$OPTARG" >&2 | ||
usage | ||
;; | ||
:) echo "Option -$OPTARG requires an argument." >&2 | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
# Check if all required arguments are provided | ||
if [ -z "$owner" ] || [ -z "$name" ] || [ -z "$pr_number" ]; then | ||
usage | ||
fi | ||
|
||
response=$(gh api graphql \ | ||
--paginate \ | ||
-F number=$pr_number -F owner=$owner -F name=$name \ | ||
-f query=' | ||
query($endCursor: String, $owner: String!, $name: String!, $number: Int!) { | ||
repository(owner: $owner, name: $name) { | ||
pullRequest(number: $number) { | ||
timelineItems(first: 10, after: $endCursor) { | ||
nodes { | ||
__typename | ||
... on UnlabeledEvent { | ||
label { | ||
name | ||
} | ||
} | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
closingIssuesReferences(first: 10, after: $endCursor) { | ||
nodes { | ||
labels(first: 10) { | ||
nodes { | ||
name | ||
} | ||
} | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
} | ||
} | ||
' --jq ' | ||
{ | ||
closing: (.data.repository.pullRequest.closingIssuesReferences.nodes | ||
| map(.labels.nodes | map(.name)) | ||
| flatten | ||
| unique), | ||
removed: (.data.repository.pullRequest.timelineItems.nodes | ||
| map(select(.__typename == "UnlabeledEvent") | .label.name) | ||
| select(length > 0) | ||
| unique) | ||
} | ||
' | ||
) | ||
|
||
echo $response |