This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathaddEmptyCommit.ts
More file actions
60 lines (51 loc) · 2.35 KB
/
addEmptyCommit.ts
File metadata and controls
60 lines (51 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { octokit } from './octokit'
import { context } from '@actions/github'
import * as core from '@actions/core'
import * as input from './shared/getInputs'
export async function addEmptyCommit() {
const contributorName: string = context?.payload?.comment?.user?.login
core.info(`Adding empty commit for ${contributorName} who has signed the CLA `)
if (context.payload.comment) {
//Do empty commit only when the contributor signs the CLA with the PR comment
if (context.payload.comment.body === 'I have read the CLA Document and I hereby sign the CLA') {
try {
const message = input.getSignedCommitMessage() ?
input.getSignedCommitMessage().replace('$contributorName', contributorName) :
` @${contributorName} has signed the CLA `
const pullRequestResponse = await octokit.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: input.getPrNumber(context.payload.issue!.number)
})
const baseCommit = await octokit.git.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: pullRequestResponse.data.head.sha
})
const tree = await octokit.git.getTree({
owner: context.repo.owner,
repo: context.repo.repo,
tree_sha: baseCommit.data.tree.sha
})
const newCommit = await octokit.git.createCommit(
{
owner: context.repo.owner,
repo: context.repo.repo,
message: message,
tree: tree.data.sha,
parents: [pullRequestResponse.data.head.sha]
}
)
return octokit.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${pullRequestResponse.data.head.ref}`,
sha: newCommit.data.sha
})
} catch (error) {
core.error(`failed when adding empty commit with the contributor's signature name: ${error} `)
}
}
}
return
}