Make import_github_pull_requests work also without gh workflows
If there are no gh workflows (./.github/workflows does not exist)
simply pick all open gh pull requests.
Change-Id: Ia8001a80fccd59e5ef31e9940ac3f324569eb335
diff --git a/Readme.md b/Readme.md
index f96cd10..531ece7 100644
--- a/Readme.md
+++ b/Readme.md
@@ -8,13 +8,13 @@
### Synopsis
-Cherry pick all PRs from github that pass your gh action PR workflow.
+Cherry pick all PRs from github (that pass your gh action PR workflow, if you have one).
### Description
This tool browses through the github pull requests concerning the project referred to by the
-`github` git remote of your current working directory and cherry picks all
-those that pass their latest github action workflow.
+`github` git remote of your current working directory and cherry picks all of them –
+or, in case there is a github action workflow, all those that pass their latest workflow.
In addition to picking the PR's commits the tool also prints out (outcommented)
bash commands that you can use to copy and paste them in your shell to:
@@ -34,7 +34,6 @@
* jq - commandline JSON processor
* `apt install jq`
* `dnf install jq`
-* currently, the tool depends on a github workflow that has tested the pull request(s)
Ideally you should also have a personal github access token (see [docuumentation](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) how to create one) and store it in the environment variable
`GITHUB_KORAP_REPO_AUTH` like in this example:
diff --git a/bin/import_github_pull_requests b/bin/import_github_pull_requests
index cb13206..4dd6e14 100755
--- a/bin/import_github_pull_requests
+++ b/bin/import_github_pull_requests
@@ -71,10 +71,15 @@
fi
fi
done <<<$(
- curl $GITHUB_KORAP_REPO_AUTH -s "https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${WORKFLOW}/runs?event=pull_request" |
- tee out.json |
+ if [ -e .github/workflows ]; then
+ curl $GITHUB_KORAP_REPO_AUTH -s "https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${WORKFLOW}/runs?event=pull_request" |
jq '.workflow_runs[] | select(.head_commit.message!="trigger github actions") | {success: (.conclusion=="success"), pr:.pull_requests[].number, sha:.pull_requests[].head.sha, message:.head_commit.message} | join(",")' |
sed 's/["]//g' | sed 's/\\n\\n.*//g'
+ else
+ curl $GITHUB_KORAP_REPO_AUTH -s "https://api.github.com/repos/${ORG}/${REPO}/pulls?state=open" |
+ jq '.[] | { success: "true", pr:.number, sha:.head.sha, message:.title} | join(",")' |
+ sed 's/["]//g' | sed 's/\\n\\n.*//g'
+ fi
)
NEWHEAD=$(git log --pretty=format:%H -1)
if [ "$NEWHEAD" == "$OLDHEAD" ]; then