Skip to content

Commit 55beb59

Browse files
committed
feat: GitHub Actions workflow to retrieve commit context information
1 parent 0073701 commit 55beb59

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Commit Context
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
get-commit-info:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
15+
- name: Run action
16+
uses: ./
17+
with:
18+
github_token: ${{ secrets.GITHUB_TOKEN }}
19+
sourceRep: ${{ github.repository }}

src/main.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as core from '@actions/core'
2-
import { wait } from './wait.js'
2+
import * as github from '@actions/github'
33

44
/**
55
* The main function for the action.
@@ -8,20 +8,22 @@ import { wait } from './wait.js'
88
*/
99
export async function run(): Promise<void> {
1010
try {
11-
const ms: string = core.getInput('milliseconds')
12-
13-
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
14-
core.debug(`Waiting ${ms} milliseconds ...`)
15-
16-
// Log the current timestamp, wait, then log the new timestamp
17-
core.debug(new Date().toTimeString())
18-
await wait(parseInt(ms, 10))
19-
core.debug(new Date().toTimeString())
20-
21-
// Set outputs for other workflow steps to use
22-
core.setOutput('time', new Date().toTimeString())
11+
// const repository: string = core.getInput('sourceRepo')
12+
const token = core.getInput('github_token', { required: true })
13+
const octokit = github.getOctokit(token)
14+
const sha = github.context.sha
15+
const { owner, repo } = github.context.repo
16+
const { data: commit } = await octokit.rest.repos.getCommit({
17+
owner,
18+
repo,
19+
ref: sha
20+
})
21+
console.log(`Commit Message: ${commit.commit.message}`)
22+
console.log(`Author Name: ${commit.commit.author?.name}`)
23+
console.log(`Author Email: ${commit.commit.author?.email}`)
24+
console.log(`Committer Name: ${commit.commit.committer?.name}`)
25+
console.log(`Committer Email: ${commit.commit.committer?.email}`)
2326
} catch (error) {
24-
// Fail the workflow run if an error occurs
2527
if (error instanceof Error) core.setFailed(error.message)
2628
}
2729
}

0 commit comments

Comments
 (0)