template-git-repo 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "template-git-repo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "One command to set up a repo with GitHub Actions, README badges, Turborepo and Codecov — the CI setup from qwksearch-research-agent, as a template",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -44,15 +44,21 @@ jobs:
|
|
|
44
44
|
--repo "$REPOSITORY" \
|
|
45
45
|
--state open \
|
|
46
46
|
--json number,isDraft,mergeStateStatus,reviewDecision,statusCheckRollup \
|
|
47
|
-
--jq '.[] | select(.isDraft == false) | select(.mergeStateStatus == "CLEAN") | select((.reviewDecision == "APPROVED"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
--jq '.[] | select(.isDraft == false) | select(.mergeStateStatus == "CLEAN") | select((.reviewDecision // "") as $decision | $decision == "APPROVED" or $decision == "") | select(all(.statusCheckRollup[]?; (.conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL"))) | .number' \
|
|
48
|
+
> "$RUNNER_TEMP/mergeable-prs.txt"
|
|
49
|
+
|
|
50
|
+
# The numbers go through a file rather than a pipe: a piped `while`
|
|
51
|
+
# runs in a subshell that shares its stdin with `gh`, and a pipeline
|
|
52
|
+
# under `pipefail` fails the step for a producer that merely had
|
|
53
|
+
# nothing to say.
|
|
54
|
+
while read -r pr_number; do
|
|
55
|
+
echo "Attempting to merge PR #${pr_number}"
|
|
56
|
+
gh pr merge "$pr_number" \
|
|
57
|
+
--repo "$REPOSITORY" \
|
|
58
|
+
--squash \
|
|
59
|
+
--delete-branch \
|
|
60
|
+
--auto || echo "Could not merge PR #${pr_number}; it may require review, checks, or conflict resolution."
|
|
61
|
+
done < "$RUNNER_TEMP/mergeable-prs.txt"
|
|
56
62
|
|
|
57
63
|
- name: Create pull requests for branches without one
|
|
58
64
|
env:
|
|
@@ -71,32 +77,43 @@ jobs:
|
|
|
71
77
|
|
|
72
78
|
base_sha="$(git rev-parse "origin/${BASE_BRANCH}")"
|
|
73
79
|
|
|
80
|
+
# Not `for-each-ref | grep | while`: `grep` exits 1 when it filters
|
|
81
|
+
# every ref out, and `pipefail` turns that into a failed run on the
|
|
82
|
+
# ordinary "only the default branch is left" case. The refs go
|
|
83
|
+
# through a file, and the ones to leave alone are skipped inside the
|
|
84
|
+
# loop, so an empty list is a no-op.
|
|
74
85
|
git for-each-ref --format='%(refname:strip=3)' refs/remotes/origin \
|
|
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
|
-
|
|
86
|
+
> "$RUNNER_TEMP/branches.txt"
|
|
87
|
+
|
|
88
|
+
while read -r branch; do
|
|
89
|
+
if [ "$branch" = "HEAD" ] || [ "$branch" = "$BASE_BRANCH" ]; then
|
|
90
|
+
continue
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
open_pr="$(gh pr list --repo "$REPOSITORY" --state open --head "$branch" --json number --jq 'length')"
|
|
94
|
+
# `merged` too: a branch whose PR was merged but which was never
|
|
95
|
+
# deleted would otherwise get a fresh PR opened on every sweep.
|
|
96
|
+
merged_pr="$(gh pr list --repo "$REPOSITORY" --state merged --head "$branch" --json number --jq 'length')"
|
|
97
|
+
branch_sha="$(git rev-parse "origin/${branch}")"
|
|
98
|
+
|
|
99
|
+
if [ "$open_pr" -gt 0 ] || [ "$merged_pr" -gt 0 ]; then
|
|
100
|
+
echo "Skipping ${branch}: a pull request already exists or was previously merged."
|
|
101
|
+
continue
|
|
102
|
+
fi
|
|
103
|
+
|
|
104
|
+
# An ancestor of the base branch has nothing to contribute; a PR
|
|
105
|
+
# for it would be empty.
|
|
106
|
+
if git merge-base --is-ancestor "$branch_sha" "$base_sha"; then
|
|
107
|
+
echo "Skipping ${branch}: it is already contained in ${BASE_BRANCH}."
|
|
108
|
+
continue
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
echo "Creating PR for ${branch} -> ${BASE_BRANCH}"
|
|
112
|
+
gh pr create \
|
|
113
|
+
--repo "$REPOSITORY" \
|
|
114
|
+
--head "$branch" \
|
|
115
|
+
--base "$BASE_BRANCH" \
|
|
116
|
+
--title "Merge ${branch} into ${BASE_BRANCH}" \
|
|
117
|
+
--body "Automated pull request for branch \`${branch}\`." \
|
|
118
|
+
|| echo "Could not open a PR for ${branch}."
|
|
119
|
+
done < "$RUNNER_TEMP/branches.txt"
|