Get Commit and Parse Details such as the head Commit Message for a Pull Request event and more...
This can be done with a simple run:
step; however, this action simplifies making the request, parsing the response, and setting the output.
View Native Alternative
- name: 'Get Commit Message'
id: commit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF: ${{ github.event.pull_request.head.sha }}
run: |
echo message=$(gh api "/repos/${GITHUB_REPOSITORY}/commits/${REF}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
--jq '.commit.message') >> "${GITHUB_OUTPUT}"
Note: This uses the --jq
option of the gh
cli as a selector for the desired data.
See some Examples of this action below...
Input | Req. | Default Value | Input Description |
---|---|---|---|
sha | - | GITHUB_SHA |
SHA of Commit |
selector | - | - | Object Selector * |
summary | - | true |
Add Summary to Job * |
token | - | github.token |
Only for PAT |
selector: JavaScript Object selector in dot notation. Examples: commit
or commit.message
summary: Write the results to the Job Summary. To disable set to: false
π View Example Job Summary
sha: d6b030c28fb4e55c233b83323ffd1b41cf47241a
Result
Updates
Commit
{
"sha": "d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"node_id": "C_kwDOONDk4toAKGQ2YjAzMGMyOGZiNGU1NWMyMzNiODMzMjNmZmQxYjQxY2Y0NzI0MWE",
"commit": {
"author": {
"name": "Shane",
"email": "6071159+smashedr@users.noreply.github.com",
"date": "2025-03-22T22:45:32Z"
},
"committer": {
"name": "Shane",
"email": "6071159+smashedr@users.noreply.github.com",
"date": "2025-03-22T22:45:32Z"
},
"message": "Updates",
"tree": {
"sha": "533436a6c0359dd3743da72acc30366d5d50fbc2",
"url": "https://api.github.com/repos/cssnr/get-commit-action/git/trees/533436a6c0359dd3743da72acc30366d5d50fbc2"
},
"url": "https://api.github.com/repos/cssnr/get-commit-action/git/commits/d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "-----BEGIN PGP SIGNATURE-----\n\niHUEABYKAB0WIQRXgKNZZbHv52xw4573HsvCBq6NtQUCZ989jAAKCRD3HsvCBq6N\ntc2QAP4xDEyh1mPoDbry+AagGQgYQzQU9pN+Q9A1nLNptiLR8gD/c5fEHeDBOIJo\nNqZCh4BACo3KFF3sXysTdqr3zWIOqwI=\n=0MJn\n-----END PGP SIGNATURE-----",
"payload": "tree 533436a6c0359dd3743da72acc30366d5d50fbc2\nparent 49ed46652824d2fa19f75ae0cb9b56b8a6563a40\nauthor Shane <6071159+smashedr@users.noreply.github.com> 1742683532 -0700\ncommitter Shane <6071159+smashedr@users.noreply.github.com> 1742683532 -0700\n\nUpdates\n",
"verified_at": "2025-03-22T22:45:07Z"
}
},
"url": "https://api.github.com/repos/cssnr/get-commit-action/commits/d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"html_url": "https://github.com/cssnr/get-commit-action/commit/d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"comments_url": "https://api.github.com/repos/cssnr/get-commit-action/commits/d6b030c28fb4e55c233b83323ffd1b41cf47241a/comments",
"author": {
"login": "smashedr",
"id": 6071159,
"node_id": "MDQ6VXNlcjYwNzExNTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6071159?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smashedr",
"html_url": "https://github.com/smashedr",
"followers_url": "https://api.github.com/users/smashedr/followers",
"following_url": "https://api.github.com/users/smashedr/following{/other_user}",
"gists_url": "https://api.github.com/users/smashedr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smashedr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smashedr/subscriptions",
"organizations_url": "https://api.github.com/users/smashedr/orgs",
"repos_url": "https://api.github.com/users/smashedr/repos",
"events_url": "https://api.github.com/users/smashedr/events{/privacy}",
"received_events_url": "https://api.github.com/users/smashedr/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"committer": {
"login": "smashedr",
"id": 6071159,
"node_id": "MDQ6VXNlcjYwNzExNTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6071159?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smashedr",
"html_url": "https://github.com/smashedr",
"followers_url": "https://api.github.com/users/smashedr/followers",
"following_url": "https://api.github.com/users/smashedr/following{/other_user}",
"gists_url": "https://api.github.com/users/smashedr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smashedr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smashedr/subscriptions",
"organizations_url": "https://api.github.com/users/smashedr/orgs",
"repos_url": "https://api.github.com/users/smashedr/repos",
"events_url": "https://api.github.com/users/smashedr/events{/privacy}",
"received_events_url": "https://api.github.com/users/smashedr/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"parents": [
{
"sha": "49ed46652824d2fa19f75ae0cb9b56b8a6563a40",
"url": "https://api.github.com/repos/cssnr/get-commit-action/commits/49ed46652824d2fa19f75ae0cb9b56b8a6563a40",
"html_url": "https://github.com/cssnr/get-commit-action/commit/49ed46652824d2fa19f75ae0cb9b56b8a6563a40"
}
],
"stats": {
"total": 2,
"additions": 1,
"deletions": 1
},
"files": [
{
"sha": "b095106eaeb1d8cd5cf78be67576080783600386",
"filename": ".github/workflows/test.yaml",
"status": "modified",
"additions": 1,
"deletions": 1,
"changes": 2,
"blob_url": "https://github.com/cssnr/get-commit-action/blob/d6b030c28fb4e55c233b83323ffd1b41cf47241a/.github%2Fworkflows%2Ftest.yaml",
"raw_url": "https://github.com/cssnr/get-commit-action/raw/d6b030c28fb4e55c233b83323ffd1b41cf47241a/.github%2Fworkflows%2Ftest.yaml",
"contents_url": "https://api.github.com/repos/cssnr/get-commit-action/contents/.github%2Fworkflows%2Ftest.yaml?ref=d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"patch": "@@ -39,7 +39,7 @@ jobs:\n #sha: dd49c0cc254760111a78f2c739efcedd567e2bf2\n \n - name: \"1: Verify Non-Pull\"\n- if: ${{ !github.event.act }}\n+ if: ${{ github.event_name != 'pull_request' }}\n env:\n COMMIT: ${{ steps.test.outputs.commit }}\n RESULT: ${{ steps.test.outputs.result }}"
}
]
}
Config
sha: "d6b030c28fb4e55c233b83323ffd1b41cf47241a"
selector: "commit.message"
summary: true
Get the commit for the SHA that triggered the workflow.
- name: 'Get Commit Action'
id: commit
uses: cssnr/get-commit-action@master
Get the head commit for a pull_request event.
- name: 'Get Commit Action'
id: commit
uses: cssnr/get-commit-action@master
with:
sha: ${{ github.event.pull_request.head.sha }}
See the Examples for more.
Output | Description |
---|---|
sha | Commit SHA |
commit | Commit JSON |
result | Parsed Results |
View Example Commit JSON
{
"sha": "d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"node_id": "C_kwDOONDk4toAKGQ2YjAzMGMyOGZiNGU1NWMyMzNiODMzMjNmZmQxYjQxY2Y0NzI0MWE",
"commit": {
"author": {
"name": "Shane",
"email": "6071159+smashedr@users.noreply.github.com",
"date": "2025-03-22T22:45:32Z"
},
"committer": {
"name": "Shane",
"email": "6071159+smashedr@users.noreply.github.com",
"date": "2025-03-22T22:45:32Z"
},
"message": "Updates",
"tree": {
"sha": "533436a6c0359dd3743da72acc30366d5d50fbc2",
"url": "https://api.github.com/repos/cssnr/get-commit-action/git/trees/533436a6c0359dd3743da72acc30366d5d50fbc2"
},
"url": "https://api.github.com/repos/cssnr/get-commit-action/git/commits/d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "-----BEGIN PGP SIGNATURE-----\n\niHUEABYKAB0WIQRXgKNZZbHv52xw4573HsvCBq6NtQUCZ989jAAKCRD3HsvCBq6N\ntc2QAP4xDEyh1mPoDbry+AagGQgYQzQU9pN+Q9A1nLNptiLR8gD/c5fEHeDBOIJo\nNqZCh4BACo3KFF3sXysTdqr3zWIOqwI=\n=0MJn\n-----END PGP SIGNATURE-----",
"payload": "tree 533436a6c0359dd3743da72acc30366d5d50fbc2\nparent 49ed46652824d2fa19f75ae0cb9b56b8a6563a40\nauthor Shane <6071159+smashedr@users.noreply.github.com> 1742683532 -0700\ncommitter Shane <6071159+smashedr@users.noreply.github.com> 1742683532 -0700\n\nUpdates\n",
"verified_at": "2025-03-22T22:45:07Z"
}
},
"url": "https://api.github.com/repos/cssnr/get-commit-action/commits/d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"html_url": "https://github.com/cssnr/get-commit-action/commit/d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"comments_url": "https://api.github.com/repos/cssnr/get-commit-action/commits/d6b030c28fb4e55c233b83323ffd1b41cf47241a/comments",
"author": {
"login": "smashedr",
"id": 6071159,
"node_id": "MDQ6VXNlcjYwNzExNTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6071159?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smashedr",
"html_url": "https://github.com/smashedr",
"followers_url": "https://api.github.com/users/smashedr/followers",
"following_url": "https://api.github.com/users/smashedr/following{/other_user}",
"gists_url": "https://api.github.com/users/smashedr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smashedr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smashedr/subscriptions",
"organizations_url": "https://api.github.com/users/smashedr/orgs",
"repos_url": "https://api.github.com/users/smashedr/repos",
"events_url": "https://api.github.com/users/smashedr/events{/privacy}",
"received_events_url": "https://api.github.com/users/smashedr/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"committer": {
"login": "smashedr",
"id": 6071159,
"node_id": "MDQ6VXNlcjYwNzExNTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6071159?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smashedr",
"html_url": "https://github.com/smashedr",
"followers_url": "https://api.github.com/users/smashedr/followers",
"following_url": "https://api.github.com/users/smashedr/following{/other_user}",
"gists_url": "https://api.github.com/users/smashedr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smashedr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smashedr/subscriptions",
"organizations_url": "https://api.github.com/users/smashedr/orgs",
"repos_url": "https://api.github.com/users/smashedr/repos",
"events_url": "https://api.github.com/users/smashedr/events{/privacy}",
"received_events_url": "https://api.github.com/users/smashedr/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"parents": [
{
"sha": "49ed46652824d2fa19f75ae0cb9b56b8a6563a40",
"url": "https://api.github.com/repos/cssnr/get-commit-action/commits/49ed46652824d2fa19f75ae0cb9b56b8a6563a40",
"html_url": "https://github.com/cssnr/get-commit-action/commit/49ed46652824d2fa19f75ae0cb9b56b8a6563a40"
}
],
"stats": {
"total": 2,
"additions": 1,
"deletions": 1
},
"files": [
{
"sha": "b095106eaeb1d8cd5cf78be67576080783600386",
"filename": ".github/workflows/test.yaml",
"status": "modified",
"additions": 1,
"deletions": 1,
"changes": 2,
"blob_url": "https://github.com/cssnr/get-commit-action/blob/d6b030c28fb4e55c233b83323ffd1b41cf47241a/.github%2Fworkflows%2Ftest.yaml",
"raw_url": "https://github.com/cssnr/get-commit-action/raw/d6b030c28fb4e55c233b83323ffd1b41cf47241a/.github%2Fworkflows%2Ftest.yaml",
"contents_url": "https://api.github.com/repos/cssnr/get-commit-action/contents/.github%2Fworkflows%2Ftest.yaml?ref=d6b030c28fb4e55c233b83323ffd1b41cf47241a",
"patch": "@@ -39,7 +39,7 @@ jobs:\n #sha: dd49c0cc254760111a78f2c739efcedd567e2bf2\n \n - name: \"1: Verify Non-Pull\"\n- if: ${{ !github.event.act }}\n+ if: ${{ github.event_name != 'pull_request' }}\n env:\n COMMIT: ${{ steps.test.outputs.commit }}\n RESULT: ${{ steps.test.outputs.result }}"
}
]
}
- name: 'Get Commit Action'
id: commit
uses: cssnr/get-commit-action@master
- name: 'Echo Output'
env:
COMMIT: ${{ steps.commit.outputs.commit }}
RESULT: ${{ steps.commit.outputs.result }}
run: |
echo "sha: ${{ steps.commit.outputs.sha }}"
echo "commit: ${COMMIT}"
echo "result: ${RESULT}"
Note: due to the way ${{}}
expressions are evaluated, multi-line output gets executed in a run block.
π‘ Click on an example heading to expand or collapse the example.
Get The Commit Message
- name: 'Get Commit Action'
id: commit
uses: cssnr/get-commit-action@master
with:
selector: 'commit.message'
- name: 'Echo Output'
env:
RESULT: ${{ steps.commit.outputs.result }}
run: |
echo "commit.message: ${RESULT}"
Get The head Commit Message for a PR
- name: 'Get Commit Action'
if: ${{ github.event_name == 'pull_request' }}
id: commit
uses: cssnr/get-commit-action@master
with:
sha: ${{ github.event.pull_request.head.sha }}
selector: 'commit.message'
- name: 'Echo Output'
env:
RESULT: ${{ steps.commit.outputs.result }}
run: |
echo "commit.message: ${RESULT}"
Get The Author's Login
- name: 'Get Commit Action'
if: ${{ github.event_name == 'pull_request' }}
id: commit
uses: cssnr/get-commit-action@master
with:
sha: ${{ github.event.pull_request.head.sha }}
selector: 'author.login'
- name: 'Echo Output'
run: |
echo "author.login: ${{ steps.commit.outputs.result }}"
More Examples Coming Soon...
For more examples, you can check out other projects using this action:
https://github.com/cssnr/get-commit-action/network/dependents
The following rolling tags are maintained.
Version Tag | Rolling | Bugs | Feat. | Name | Target | Example |
---|---|---|---|---|---|---|
β | β | β | Major | vN.x.x |
vN |
|
β | β | β | Minor | vN.N.x |
vN.N |
|
β | β | β | Micro | vN.N.N |
vN.N.N |
You can view the release notes for each version on the releases page.
The Major tag is recommended. It is the most up-to-date and always backwards compatible. Breaking changes would result in a Major version bump. At a minimum you should use a Minor tag.
For general help or to request a feature, see:
- Q&A Discussion: https://github.com/cssnr/get-commit-action/discussions/categories/q-a
- Request a Feature: https://github.com/cssnr/get-commit-action/discussions/categories/feature-requests
If you are experiencing an issue/bug or getting unexpected results, you can:
- Report an Issue: https://github.com/cssnr/get-commit-action/issues
- Chat with us on Discord: https://discord.gg/wXy6m2X8wY
- Provide General Feedback: https://cssnr.github.io/feedback/
For more information, see the CSSNR SUPPORT.md.
Currently, the best way to contribute to this project is to star this project on GitHub.
For more information, see the CSSNR CONTRIBUTING.md.
Additionally, you can support other GitHub Actions I have published:
- Stack Deploy Action
- Portainer Stack Deploy
- VirusTotal Action
- Mirror Repository Action
- Update Version Tags Action
- Update JSON Value Action
- Parse Issue Form Action
- Cloudflare Purge Cache Action
- Mozilla Addon Update Action
- Docker Tags Action
- Package Changelog Action
- NPM Outdated Check Action
For a full list of current projects to support visit: https://cssnr.github.io/