8bitjonny / gh-get-current-pr Goto Github PK
View Code? Open in Web Editor NEWGithub Action for getting all the details about the current Pull Request if the commit is part of one
License: GNU General Public License v3.0
Github Action for getting all the details about the current Pull Request if the commit is part of one
License: GNU General Public License v3.0
Default branch not working
I use it with this configuration. When I try launch an action after deploy it's currently working everywhere execpt on the default branch (which is development on my project)
on:
deployment_status:
branches:
- development
- staging
- main
When you try to use it on a deployment_status github action it's currently not working if you are the default branch
Describe your issue here.
Tell us how to reproduce this issue. Please provide a working demo, you can use this template as a base.
Tell us what should happen
Tell us what happens instead
I may be wrong but it seems that the action does not find the corresponding PR when it is a PR across forks.
- name: Get PR object
if: failure()
uses: 8BitJonny/[email protected]
id: failed_pr_number
with:
sha: ${{ github.event.pull_request.head.sha }}
- name: Debug GetPR output
if: failure()
run: |
echo ${{ steps.failed_pr_number.outputs.number }}
I guess just make a PR between forks should make it reproducible.
I was expecting to find the good PR number
Tell us what happens instead
if I have 2 branches, one with a PR associated with it, and one not,
and I push the same commit to both branches in github.
expected - when the action executes one of the branches should detects a PR exists and return a number, the other one should not.
actual - both branches find the same associated PR and return the same associated PR number.
this makes using this scheme kinda dangerous, as side-effects - publishing, overwriting pre-release artifacts etc will occur from unexpected branches.
a convenience option to compare the head.label or ref with the current branch would be very helpful.
Instead of just filtering open, we should be able to filter draft pull requests too.
GitHub urges all actions to update nodejs to 20
I'm putting this up here for now, can probably submit a pr in a while..:P
When I comment on an issue, a ci run starts and fails.
n/a
See this log: https://github.com/8BitJonny/gh-get-current-pr/actions/runs/6537248706
I can comment without being notified about a build failure.
I'm notified about a build failure.
This Repo is slowly growing and getting more and more used. A proper testing workflow integrated into the CI is more that overdue
Clarification on documentation. I am wondering if I am interpreting it correctly that if the outcome
of the action is that the commit is NOT part of a PR, it will not return success
?
In my testing, it is returning success
regardless of it a PR exists. So using the conditional if: steps.PR.outcome == 'success'
doesn't really help me in directing things depending on if it is a PR or not.
I am able to use this how I need it by focusing on the pr number output, however the outcome being successful seems strange to me?
thanks for creating this!
using a self-hosted github runner in github enterprise v3.7 (latest)
In theory this should work everywhere and not require my environment. My workflow is below.
If commit is not part of a PR, action will not return success
success is returned regardless. However the PR information outputs are empty.
Workflow:
name: Workflow
on:
push:
branches-ignore:
- main
# stops current jobs if a new commit is pushed to the branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
PR:
runs-on: [dev, terraform]
outputs:
PR_STATUS: ${{ steps.pr-check.outputs.PR_STATUS }}
PR_NUMBER: ${{ steps.PR.outputs.number }}
PR_OUTCOME: ${{ steps.PR.outcome }}
steps:
- uses: synced-actions/[email protected]
id: PR
- id: pr-check
run: |
if [ ${{ steps.PR.outputs.number }} == 0 ]; then
echo "PR_STATUS=false" >> $GITHUB_OUTPUT
else
echo "PR_STATUS=true" >> $GITHUB_OUTPUT
fi
test:
needs: PR
runs-on: [dev, terraform]
steps:
- run: |
echo "Status:" ${{ needs.PR.outputs.PR_STATUS }} and Number: ${{ needs.PR.outputs.PR_NUMBER }}""
- if: needs.PR.outputs.PR_STATUS == true
run: |
echo "TRUE PR status is ${{ needs.PR.outputs.PR_STATUS }}"
- if: needs.PR.outputs.PR_STATUS != true
run: |
echo "FALSE PR status : ${{ needs.PR.outputs.PR_STATUS }}"
- if: needs.PR.outputs.PR_NUMBER == 0
run: |
echo "empty PR NUMBER : ${{ needs.PR.outputs.PR_NUMBER }}"
- if: needs.PR.outputs.PR_NUMBER != 0
run: |
echo "existing PR NUMBER is ${{ needs.PR.outputs.PR_NUMBER }}"
When I changed my code to
- uses: 8BitJonny/[email protected]
it worked (notice the no v
-- 1.0.1
is the tag name you have)
When I run the workflow I get the following error because the node_modules
folder is not committed to the action's repository:
internal/modules/cjs/loader.js:800
throw err;
^
Error: Cannot find module '@actions/core'
Require stack:
- /home/runner/work/_actions/8BitJonny/gh-get-current-pr/1.0.0/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/runner/work/_actions/8BitJonny/gh-get-current-pr/1.0.0/index.js:7:44)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/runner/work/_actions/8BitJonny/gh-get-current-pr/1.0.0/index.js'
]
}
Could you please commit the node_modules as well?
Warning: The set-output
command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Trying to get this action to work although I either get an empty JSON or an error.
I've added in my action file below
name: Pull Request Lint
on:
pull_request:
types: ['opened', 'edited', 'synchronize', 'reopened']
jobs:
pr_linter:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Lint branch name and PR title
uses: aschbacd/[email protected]
with:
commit-message-subject-max-length: 100
re-commit-message-subject: .*
re-branch-name: '^[0-9]{4}-'
re-pull-request-title: '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)'
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6
- name: Running on a pull request branch.
id: extract_branch
if: steps.branch-name.outputs.is_default == 'false'
run: |
echo "Running on pr: ${{ steps.branch-name.outputs.current_branch }}"
echo "branch_name=${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_ENV
- name: step1
id: step1
run: echo 'step_1_json={"a":1}' >> $GITHUB_ENV
if: true
- name: step2
run: echo $A && echo $B && echo $C
env:
A: ${{ env.step_1_json && fromJSON(env.step_1_json).a }}
B: ${{ env.step_1_json }}
C: ${{ fromJSON(env.step_1_json).a }}
if: true
- uses: 8BitJonny/[email protected]
id: PR
with:
sha: ${{ github.event.pull_request.head.sha }}
- run: echo "PR ${prNumber} ${prTitle} at ${prUrl}"
if: steps.PR.outcome == 'success'
env:
# TODO: try and get JSON object with the full PR object working
# toJSON(fromJSON(...pr)) parses it into memory and then format is with pretty-print.
prJSON: ${{ toJSON(fromJSON(steps.current_pr.outputs.pr)) }}
# Direct access to common PR properties
prNumber: ${{ steps.PR.outputs.number }}
prUrl: ${{ steps.PR.outputs.pr_url }}
prTitle: ${{ steps.PR.outputs.pr_title }}
prBody: ${{ steps.PR.outputs.pr_body }}
prCreatedAt: ${{ steps.PR.outputs.pr_created_at }}
prMergedAt: ${{ steps.PR.outputs.pr_merged_at }}
prClosedAt: ${{ steps.PR.outputs.pr_closed_at }}
prLabel: ${{ steps.PR.outputs.pr_labels }}
- if: ${{ steps.PR.outputs.pr_body }} != 'Fixed AB#${{ env.branch_name }}'
uses: DerekRoberts/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# add_markdown: Fixed AB#${{ env.branch_name }}
Run the action
It does not error and I get a JSON back
I get an error and/or empty JSON returned.
I gave this a whirl, but it doesn't seem to work for forced push on a PR.
If the latest commit is a merge commit, it can't find the pull request associated.
The action is not working
I have a step that is like that:
- name: Fetch PR
if: ${{ github.event.pull_request }}
uses: 8BitJonny/[email protected]
- name: Rebase PR with target
if: ${{ github.event.pull_request }}
run: |
git rebase $GITHUB_BASE_REF
git log $GITHUB_BASE_REF..HEAD --pretty=format:"%h - %s (%an)"
To fetch the current PR
It's failing
the action doesn't return api data on closed pr event
I have two github jobs one is to get the data using this repo action and one is a job that triggered when a pr is closed
jobs:
get-pr:
runs-on: ubuntu-latest
outputs:
PR: ${{steps.PR.outputs.pr}}
steps:
- name: Find Pull Request
uses: 8BitJonny/[email protected]
id: PR
with:
sha: ${{ github.event.pull_request.head.sha }}
closed_by_user:
timeout-minutes: 30
needs: get-pr
if: needs.get-pr.outputs.PR != '' && github.event.pull_request.merged == false && github.event.pull_request.closed
runs-on: ubuntu-latest
steps:
.....
with the following if condition on the job
needs.get-pr.outputs.PR != '' && github.event.pull_request.merged == false && github.event.pull_request.closed
needs.get-pr.outputs.PR return json data , the job will triggered
the closed_by_user
jobs didn't run because the needs.get-pr.outputs.PR didn't return any json data
when I removed the needs.get-pr.outputs.PR != ''
the job is triggered, but got error since I need a data from the API, but the data is empty
I created a PR with the title: fix!: Something (something)
It's a closed repo
Create a PR with (
or )
in the title and try to call. I didn't check for other special chars
- name: Information
run: |
echo Base PR URL: ${{ steps.PR.outputs.pr_url }}
echo Based On PR Title: ${{ steps.PR.outputs.pr_title }}
Should output the info about the PR
Run echo Base PR URL: https://github.com/***/pull/22
/home/runner/work/_temp/547790f0-2141-4ff[8](https://github.com/***o/runs/7837860134?check_suite_focus=true#step:6:9)-b1b6-5d0fdf8883c8.sh: line 2: syntax error near unexpected token `('
Base PR URL: https://github.com/****/pull/22
Error: Process completed with exit code 2.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.