Skip to content

Commit 8f5bec8

Browse files
for testing
1 parent 53779f5 commit 8f5bec8

File tree

4 files changed

+112
-112
lines changed

4 files changed

+112
-112
lines changed

lib/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ function run() {
2626
signale_1.default.info('This is not target event.');
2727
return;
2828
}
29-
signale_1.default.info(`Tag name: ${github_1.context.payload.release.tag_name}`);
29+
// signale.info(`Tag name: ${context.payload.release.tag_name}`);
3030
const octokit = new github_1.GitHub(core_1.getInput('GITHUB_TOKEN', { required: true }));
3131
yield command_1.clone(github_1.context);
3232
yield command_1.runBuild();
3333
const files = yield command_1.getDiffFiles();
3434
signale_1.default.info(`Diff files count: ${files.length}`);
3535
if (!files.length)
3636
return;
37-
yield github_2.push(files, github_1.context.payload.release.tag_name, octokit, github_1.context);
37+
// await push(files, context.payload.release.tag_name, octokit, context);
38+
yield github_2.push(files, 'test', octokit, github_1.context);
3839
}
3940
catch (error) {
4041
core_1.setFailed(error.message);

lib/utils/github.js

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1111
return (mod && mod.__esModule) ? mod : { "default": mod };
1212
};
1313
Object.defineProperty(exports, "__esModule", { value: true });
14-
// import fs from 'fs';
15-
// import path from 'path';
14+
const fs_1 = __importDefault(require("fs"));
15+
const path_1 = __importDefault(require("path"));
1616
const signale_1 = __importDefault(require("signale"));
17-
// import {getCommitMessage, getWorkspace} from './misc';
18-
const command_1 = require("./command");
17+
const misc_1 = require("./misc");
18+
// import {commit} from './command';
1919
exports.push = (files, name, octokit, context) => __awaiter(this, void 0, void 0, function* () {
20-
// const commit = await createCommit(files, octokit, context);
21-
// await updateRef(commit.data.sha, name, octokit, context);
22-
yield updateRef(yield command_1.commit(), name, octokit, context);
20+
const commit = yield createCommit(files, octokit, context);
21+
yield updateRef(commit.data.sha, name, octokit, context);
22+
// await updateRef(await commit(), name, octokit, context);
23+
});
24+
const getCommit = (octokit, context) => __awaiter(this, void 0, void 0, function* () {
25+
return yield octokit.git.getCommit({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
commit_sha: context.sha,
29+
});
2330
});
24-
// const getCommit = async (octokit: GitHub, context: Context) => {
25-
// return await octokit.git.getCommit({
26-
// owner: context.repo.owner,
27-
// repo: context.repo.repo,
28-
// commit_sha: context.sha,
29-
// });
30-
// };
3131
const existsRef = (name, octokit, context) => {
3232
return new Promise(resolve => {
3333
octokit.git.getRef({
@@ -42,17 +42,17 @@ const existsRef = (name, octokit, context) => {
4242
});
4343
};
4444
const getRef = (name) => `refs/heads/${name}`;
45-
// const createBlob = async (filePath: string, octokit: GitHub, context: Context) => {
46-
// const file = path.resolve(getWorkspace(), filePath);
47-
// const isExists = fs.existsSync(file);
48-
// const blob = await octokit.git.createBlob({
49-
// owner: context.repo.owner,
50-
// repo: context.repo.repo,
51-
// content: isExists ? Buffer.from(fs.readFileSync(file)).toString('base64') : '',
52-
// encoding: 'base64',
53-
// });
54-
// return ({path: filePath, sha: blob.data.sha});
55-
// };
45+
const createBlob = (filePath, octokit, context) => __awaiter(this, void 0, void 0, function* () {
46+
const file = path_1.default.resolve(misc_1.getWorkspace(), filePath);
47+
const isExists = fs_1.default.existsSync(file);
48+
const blob = yield octokit.git.createBlob({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
content: isExists ? Buffer.from(fs_1.default.readFileSync(file)).toString('base64') : '',
52+
encoding: 'base64',
53+
});
54+
return ({ path: filePath, sha: blob.data.sha });
55+
});
5656
const createRef = (name, octokit, context) => __awaiter(this, void 0, void 0, function* () {
5757
signale_1.default.info(`Create Ref: ${name}`);
5858
yield octokit.git.createRef({
@@ -62,35 +62,33 @@ const createRef = (name, octokit, context) => __awaiter(this, void 0, void 0, fu
6262
sha: context.sha,
6363
});
6464
});
65-
// const filesToBlobs = async (files: object, octokit: GitHub, context: Context) => Object.values(files).map(async file => await createBlob(file, octokit, context));
66-
//
67-
// const createTree = async (blobs: object, octokit: GitHub, context: Context) => {
68-
// signale.info('Create Tree');
69-
// return await octokit.git.createTree({
70-
// owner: context.repo.owner,
71-
// repo: context.repo.repo,
72-
// base_tree: (await getCommit(octokit, context)).data.tree.sha,
73-
// tree: Object.values(blobs).map(blob => ({
74-
// path: blob.path,
75-
// type: 'blob',
76-
// mode: '100644',
77-
// sha: blob.sha,
78-
// })),
79-
// });
80-
// };
81-
//
82-
// const createCommit = async (files: object, octokit: GitHub, context: Context) => {
83-
// const blobs = await filesToBlobs(files, octokit, context);
84-
// const tree = await createTree(blobs, octokit, context);
85-
// signale.info('Create Commit');
86-
// return await octokit.git.createCommit({
87-
// owner: context.repo.owner,
88-
// repo: context.repo.repo,
89-
// tree: tree.data.sha,
90-
// parents: [context.sha],
91-
// message: getCommitMessage(),
92-
// });
93-
// };
65+
const filesToBlobs = (files, octokit, context) => __awaiter(this, void 0, void 0, function* () { return Object.values(files).map((file) => __awaiter(this, void 0, void 0, function* () { return yield createBlob(file, octokit, context); })); });
66+
const createTree = (blobs, octokit, context) => __awaiter(this, void 0, void 0, function* () {
67+
signale_1.default.info('Create Tree');
68+
return yield octokit.git.createTree({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
base_tree: (yield getCommit(octokit, context)).data.tree.sha,
72+
tree: Object.values(blobs).map(blob => ({
73+
path: blob.path,
74+
type: 'blob',
75+
mode: '100644',
76+
sha: blob.sha,
77+
})),
78+
});
79+
});
80+
const createCommit = (files, octokit, context) => __awaiter(this, void 0, void 0, function* () {
81+
const blobs = yield filesToBlobs(files, octokit, context);
82+
const tree = yield createTree(blobs, octokit, context);
83+
signale_1.default.info('Create Commit');
84+
return yield octokit.git.createCommit({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
tree: tree.data.sha,
88+
parents: [context.sha],
89+
message: misc_1.getCommitMessage(),
90+
});
91+
});
9492
const updateRef = (commit, name, octokit, context) => __awaiter(this, void 0, void 0, function* () {
9593
if (!(yield existsRef(name, octokit, context))) {
9694
yield createRef(name, octokit, context);

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ async function run() {
1414
return;
1515
}
1616

17-
signale.info(`Tag name: ${context.payload.release.tag_name}`);
17+
// signale.info(`Tag name: ${context.payload.release.tag_name}`);
1818
const octokit = new GitHub(getInput('GITHUB_TOKEN', {required: true}));
1919
await clone(context);
2020
await runBuild();
2121
const files = await getDiffFiles();
2222
signale.info(`Diff files count: ${files.length}`);
2323
if (!files.length) return;
2424

25-
await push(files, context.payload.release.tag_name, octokit, context);
25+
// await push(files, context.payload.release.tag_name, octokit, context);
26+
await push(files, 'test', octokit, context);
2627
} catch (error) {
2728
setFailed(error.message);
2829
}

src/utils/github.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
// import fs from 'fs';
2-
// import path from 'path';
1+
import fs from 'fs';
2+
import path from 'path';
33
import signale from 'signale';
44
import {GitHub} from '@actions/github/lib/github';
55
import {Context} from '@actions/github/lib/context';
6-
// import {getCommitMessage, getWorkspace} from './misc';
7-
import {commit} from './command';
6+
import {getCommitMessage, getWorkspace} from './misc';
7+
// import {commit} from './command';
88

99
export const push = async (files: object, name: string, octokit: GitHub, context: Context) => {
10-
// const commit = await createCommit(files, octokit, context);
11-
// await updateRef(commit.data.sha, name, octokit, context);
12-
await updateRef(await commit(), name, octokit, context);
10+
const commit = await createCommit(files, octokit, context);
11+
await updateRef(commit.data.sha, name, octokit, context);
12+
// await updateRef(await commit(), name, octokit, context);
1313
};
1414

15-
// const getCommit = async (octokit: GitHub, context: Context) => {
16-
// return await octokit.git.getCommit({
17-
// owner: context.repo.owner,
18-
// repo: context.repo.repo,
19-
// commit_sha: context.sha,
20-
// });
21-
// };
15+
const getCommit = async (octokit: GitHub, context: Context) => {
16+
return await octokit.git.getCommit({
17+
owner: context.repo.owner,
18+
repo: context.repo.repo,
19+
commit_sha: context.sha,
20+
});
21+
};
2222

2323
const existsRef = (name: string, octokit: GitHub, context: Context) => {
2424
return new Promise<boolean>(resolve => {
@@ -36,17 +36,17 @@ const existsRef = (name: string, octokit: GitHub, context: Context) => {
3636

3737
const getRef = (name: string) => `refs/heads/${name}`;
3838

39-
// const createBlob = async (filePath: string, octokit: GitHub, context: Context) => {
40-
// const file = path.resolve(getWorkspace(), filePath);
41-
// const isExists = fs.existsSync(file);
42-
// const blob = await octokit.git.createBlob({
43-
// owner: context.repo.owner,
44-
// repo: context.repo.repo,
45-
// content: isExists ? Buffer.from(fs.readFileSync(file)).toString('base64') : '',
46-
// encoding: 'base64',
47-
// });
48-
// return ({path: filePath, sha: blob.data.sha});
49-
// };
39+
const createBlob = async (filePath: string, octokit: GitHub, context: Context) => {
40+
const file = path.resolve(getWorkspace(), filePath);
41+
const isExists = fs.existsSync(file);
42+
const blob = await octokit.git.createBlob({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
content: isExists ? Buffer.from(fs.readFileSync(file)).toString('base64') : '',
46+
encoding: 'base64',
47+
});
48+
return ({path: filePath, sha: blob.data.sha});
49+
};
5050

5151
const createRef = async (name: string, octokit: GitHub, context: Context) => {
5252
signale.info(`Create Ref: ${name}`);
@@ -58,35 +58,35 @@ const createRef = async (name: string, octokit: GitHub, context: Context) => {
5858
});
5959
};
6060

61-
// const filesToBlobs = async (files: object, octokit: GitHub, context: Context) => Object.values(files).map(async file => await createBlob(file, octokit, context));
62-
//
63-
// const createTree = async (blobs: object, octokit: GitHub, context: Context) => {
64-
// signale.info('Create Tree');
65-
// return await octokit.git.createTree({
66-
// owner: context.repo.owner,
67-
// repo: context.repo.repo,
68-
// base_tree: (await getCommit(octokit, context)).data.tree.sha,
69-
// tree: Object.values(blobs).map(blob => ({
70-
// path: blob.path,
71-
// type: 'blob',
72-
// mode: '100644',
73-
// sha: blob.sha,
74-
// })),
75-
// });
76-
// };
77-
//
78-
// const createCommit = async (files: object, octokit: GitHub, context: Context) => {
79-
// const blobs = await filesToBlobs(files, octokit, context);
80-
// const tree = await createTree(blobs, octokit, context);
81-
// signale.info('Create Commit');
82-
// return await octokit.git.createCommit({
83-
// owner: context.repo.owner,
84-
// repo: context.repo.repo,
85-
// tree: tree.data.sha,
86-
// parents: [context.sha],
87-
// message: getCommitMessage(),
88-
// });
89-
// };
61+
const filesToBlobs = async (files: object, octokit: GitHub, context: Context) => Object.values(files).map(async file => await createBlob(file, octokit, context));
62+
63+
const createTree = async (blobs: object, octokit: GitHub, context: Context) => {
64+
signale.info('Create Tree');
65+
return await octokit.git.createTree({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
base_tree: (await getCommit(octokit, context)).data.tree.sha,
69+
tree: Object.values(blobs).map(blob => ({
70+
path: blob.path,
71+
type: 'blob',
72+
mode: '100644',
73+
sha: blob.sha,
74+
})),
75+
});
76+
};
77+
78+
const createCommit = async (files: object, octokit: GitHub, context: Context) => {
79+
const blobs = await filesToBlobs(files, octokit, context);
80+
const tree = await createTree(blobs, octokit, context);
81+
signale.info('Create Commit');
82+
return await octokit.git.createCommit({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
tree: tree.data.sha,
86+
parents: [context.sha],
87+
message: getCommitMessage(),
88+
});
89+
};
9090

9191
const updateRef = async (commit: string, name: string, octokit: GitHub, context: Context) => {
9292
if (!await existsRef(name, octokit, context)) {

0 commit comments

Comments
 (0)