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 pathpersistence.ts
More file actions
78 lines (68 loc) · 2.78 KB
/
persistence.ts
File metadata and controls
78 lines (68 loc) · 2.78 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { context } from '@actions/github'
import { ReactedCommitterMap } from '../interfaces'
import { GitHub } from '@actions/github/lib/utils'
import { getDefaultOctokitClient, getPATOctokit } from '../octokit'
import * as input from '../shared/getInputs'
export async function getFileContent(): Promise<any> {
const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()
const result = await octokitInstance.repos.getContent({
owner: input.getRemoteOrgName() || context.repo.owner,
repo: input.getRemoteRepoName() || context.repo.repo,
path: input.getPathToSignatures(),
ref: input.getBranch()
})
return result
}
export async function createFile(contentBinary): Promise<any> {
const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()
return octokitInstance.repos.createOrUpdateFileContents({
owner: input.getRemoteOrgName() || context.repo.owner,
repo: input.getRemoteRepoName() || context.repo.repo,
path: input.getPathToSignatures(),
message:
input.getCreateFileCommitMessage() ||
'Creating file for storing CLA Signatures',
content: contentBinary,
branch: input.getBranch()
})
}
export async function updateFile(
sha: string,
claFileContent,
reactedCommitters: ReactedCommitterMap
): Promise<any> {
const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()
const pullRequestNo = input.getPrNumber(context.issue.number)
const owner = context.issue.owner
const repo = context.issue.repo
claFileContent?.signedContributors.push(...reactedCommitters.newSigned)
let contentString = JSON.stringify(claFileContent, null, 2)
let contentBinary = Buffer.from(contentString).toString('base64')
await octokitInstance.repos.createOrUpdateFileContents({
owner: input.getRemoteOrgName() || context.repo.owner,
repo: input.getRemoteRepoName() || context.repo.repo,
path: input.getPathToSignatures(),
sha,
message: input.getSignedCommitMessage()
? input
.getSignedCommitMessage()
.replace('$contributorName', context.actor)
// .replace('$pullRequestNo', pullRequestNo.toString())
.replace('$owner', owner)
.replace('$repo', repo)
: `@${context.actor} has signed the CLA in ${owner}/${repo}#${pullRequestNo}`,
content: contentBinary,
branch: input.getBranch()
})
}
function isRemoteRepoOrOrgConfigured(): boolean {
let isRemoteRepoOrOrgConfigured = false
if (input?.getRemoteRepoName() || input.getRemoteOrgName()) {
isRemoteRepoOrOrgConfigured = true
return isRemoteRepoOrOrgConfigured
}
return isRemoteRepoOrOrgConfigured
}