Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sicherheitslücken (CVE)USN-8797-1: GStreamer Base Plugins vulnerability(21.09.2026 um 20:05 Uhr)
Sichere ProgrammierungYou can build HTML emails with Tailwind CSS(21.09.2026 um 22:15 Uhr)
Sichere ProgrammierungDEV-Part-1-Backend.md(21.09.2026 um 22:24 Uhr)
Sichere ProgrammierungWhat It Actually Costs to Serve a 1M-Token Model in Production(21.09.2026 um 22:33 Uhr)
Sichere ProgrammierungHow to Check an Agent's Diagnosis Before It Touches Production(21.09.2026 um 22:53 Uhr)
Linux Tipps & HardeningWhat if Spotify was self-hosted? I think I got pretty close.(21.09.2026 um 22:33 Uhr)
Linux Tipps & HardeningSandboxing on Linux(21.09.2026 um 22:45 Uhr)
Sicherheitslücken (CVE)USN-8797-1: GStreamer Base Plugins vulnerability(21.09.2026 um 20:05 Uhr)
Sichere ProgrammierungYou can build HTML emails with Tailwind CSS(21.09.2026 um 22:15 Uhr)
Sichere ProgrammierungDEV-Part-1-Backend.md(21.09.2026 um 22:24 Uhr)
Sichere ProgrammierungWhat It Actually Costs to Serve a 1M-Token Model in Production(21.09.2026 um 22:33 Uhr)
Sichere ProgrammierungHow to Check an Agent's Diagnosis Before It Touches Production(21.09.2026 um 22:53 Uhr)
Linux Tipps & HardeningWhat if Spotify was self-hosted? I think I got pretty close.(21.09.2026 um 22:33 Uhr)
Linux Tipps & HardeningSandboxing on Linux(21.09.2026 um 22:45 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Get GitHub PR from commit hash

Have you ever needed to get GitHub PR details from the commit hash in the master branch? With the Merge commits strategy, number of PR will be in the commit message. But what about Rebase and merge or Squash and merge strategy? 🇨🇿 V če…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Have you ever needed to get GitHub PR details from the commit hash in the master branch? With the Merge commits strategy, number of PR will be in the commit message. But what about Rebase and merge or Squash and merge strategy?







🇨🇿 V češtině si lze článek přečíst na kutac.cz







Lately, I have modified GitHub Action, which sends Slack message with the author of the last PR that was merged. But how to get the PR number and the author of that PR when I only have a log history?






Merge commit strategy



As I wrote above, when using the Merge commit strategy, GitHub creates a merge commit with a message that looks like this:




Merge pull request #270 from author/branch-name

fix: here is your original commit message






Here it is easy to extract the number. But before merging, the user can modify the message and the number of PR will be gone or different.






I have only commit hash



Browsing in git history with git log or similar, will not tell you much. But with GitHub API, you can ask which PR contains some commit hash.



And the best about that is, it works well in all scenarios! Including Rebase and merge and Squash and merge strategies, which create new commit. So the commit in the original PR and in the master branch have different hash.



The script below uses GitHub CLI which is pre-installed inside GitHub Actions, and by setting GH_TOKEN also authenticated.




jobs:
your-action-name:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 10 # We are going to history a bit, so load little more to be sure

- name: Get last PR author
id: release-author
env:
GH_TOKEN: ${{ github.token }}
run: |
# Get last commit SHA
last_commit_sha=$(git --no-pager log --format=%H --no-merges -n 1 --skip 1) || last_commit_sha=""
author="unknown"

if [ -n "$last_commit_sha" ]; then
author=$(gh pr list --search $last_commit_sha --state merged --json author --jq '.[0].author.login') || author=""
fi

echo "author: $author"










I need to explain script above



git --no-pager log --format=%H --no-merges -n 1 --skip 1





  • git log operates on top of the git history


  • --no-pager turns off pagination - not necessary


  • --format=%H prints only full commit hash


  • --no-merges will skip merge commits


  • -n 1 --skip 1 instruct to return only 1 commit (-n) and --skip last one. This is important for us, as the last commit is created by Release please action. Remove skipping if not needed for you.



gh pr list --search $last_commit_sha --state merged --json author --jq '.[0].author.login'





  • gh pr list is using GitHub CLI to list PRs, already pre-installed in GitHub action


  • --search $last_commit_sha is a general search query, so we are searching by our commit hash


  • --state merged include only merged PRs


  • --json author --jq '.[0].author.login' tells the CLI tool to return JSON with the author field, which is then filtered by jq expression to give us the login of the first author






Is this bulletproof?



No, it is not, because it is using a generic search query. So if someone adds commit directly to comments, this will fail.



In that case, you can improve a query a bit to exclude comments from search --search "{$last_commit_sha} \!in:comments".



Or you can select author together with commits of PR, and then using JQ filter it out. It is however more complex, but also more reliable not to give false positives.




gh pr list --search $last_commit_sha --state=merged \
--json author,commits \
--jq '.[] | select(.commits[]?.oid == "'"$last_commit_sha"'") | .author.login'






If you spot another possible issue, share it with us in comments.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Get GitHub PR from commit hash

Thematisch verwandte Begriffe: GitHub, from, commit, hash · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-45381 | Tautulli is a Python based monitoring and tracking tool for Plex Media S…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick