generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-signature.js
49 lines (42 loc) · 1.29 KB
/
generate-signature.js
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
import { createSignature, commitToString } from "github-api-signature";
const privateKey: string = `-----BEGIN PGP PRIVATE KEY BLOCK-----
// Private key content //
-----END PGP PRIVATE KEY BLOCK-----`;
const passphrase = "my secret phrase";
const commit = {
message: "Commit message",
tree: "tree-sha",
parents: ["parent-sha"],
author: {
name: "John Doe",
email: "[email protected]",
date: "2018-01-01T00:00:00.000Z",
},
// Optional committer informations
// Defaults to <author>
committer: {
name: "Dohn Joe",
email: "[email protected]",
date: "2018-01-01T00:00:00.000Z",
},
};
// Using a CommitPayload object
createSignature(commit, privateKey, passphrase).then((signature: string) => {
// signature = `-----BEGIN PGP SIGNATURE-----
//
// // Signature content
// -----END PGP SIGNATURE-----`;
const apiPayload = {
...commit,
signature,
};
// Use signature with GitHub API
// https://developer.github.com/v3/git/commits/#create-a-commit
// POST /repos/:owner/:repo/git/commits
});
// Using a git-computed commit payload string
// commitToString returns the same format as "git cat-file -p <commit-sha>"
const commitStr = commitToString(commit);
createSignature(commitStr, privateKey, passphrase).then((signature) => {
console.log(signature);
});