8000 feat(*): next try · shiftcode/github-action-skip@29969f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29969f7

Browse files
feat(*): next try
1 parent 3aafbe7 commit 29969f7

File tree

7 files changed

+162
-236
lines changed

7 files changed

+162
-236
lines changed

lib/lab.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/main.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
1818
__setModuleDefault(result, mod);
1919
return result;
2020
};
21+
var __importDefault = (this && this.__importDefault) || function (mod) {
22+
return (mod && mod.__esModule) ? mod : { "default": mod };
23+
};
2124
Object.defineProperty(exports, "__esModule", { value: true });
2225
const core = __importStar(require("@actions/core"));
2326
const github = __importStar(require("@actions/github"));
24-
const child_process_1 = require("child_process");
27+
const https_1 = __importDefault(require("https"));
2528
var INPUT_PARAMS;
2629
(function (INPUT_PARAMS) {
2730
INPUT_PARAMS["SKIP_ON_COMMIT_MSG"] = "skipOnCommitMsg";
@@ -55,14 +58,18 @@ async function run() {
5558
}
5659
core.info(`sha: ${sha}`);
5760
if (sha) {
58-
const commitMessage = (0, child_process_1.execSync)(`git log --format=%B -n 1 ${sha}`, { encoding: 'utf8' }).trim();
61+
// const commitMessage = execSync(`git log --format=%B -n 1 ${sha}`, { encoding: 'utf8' }).trim()
5962
// const q = `hash:${sha}`
6063
// console.info(`q: ${q}`)
6164
// const response = await fetch(`https://api.github.com/repos/shiftcode/sc-commons/git/commits/${sha}`, { headers: new Headers({ Authorization: `token ${ghToken}` }) })
6265
// if (response.status >= 200 && response.status < 300) {
6366
// // ok
6467
// const commit = await response.json() as { message: string }
6568
// const commitMessage = commit.message as string
69+
const url = `https://api.github.com/repos/${github.context.payload.repository}/git/commits/${sha}`;
70+
console.log('fetch with url', url);
71+
const commit = (await fetch(url, ghToken)); /* and others */
72+
const commitMessage = commit.message;
6673
core.info(`commit message to check against ${commitMessage}`);
6774
if (commitMessage.includes(skipOnCommitMsg)) {
6875
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, false);
@@ -87,4 +94,22 @@ async function run() {
8794
}
8895
}
8996
}
97+
async function fetch(url, token) {
98+
return new Promise((resolve) => {
99+
https_1.default.get(url, {
100+
headers: {
101+
Authorization: `token ${token}`,
102+
'User-Agent': 'Github Skip Action',
103+
},
104+
}, res => {
105+
let data = '';
106+
res.on('data', chunk => {
107+
data += chunk;
108+
});
109+
res.on('end', () => {
110+
resolve(JSON.parse(data));
111+
});
112+
});
113+
});
114+
}
90115
run();

lib/octokit-lab.js

Lines changed: 48 additions & 20 deletions
< 6D47 td data-grid-cell-id="diff-fb522e02f03d926bdba903915e1671c4a35b2a46a7fd1d6e3b0936a316cf29c7-27-22-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">27
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,59 @@ var __importStar = (this && this.__importStar) || function (mod) {
2020
};
2121
Object.defineProperty(exports, "__esModule", { value: true });
2222
const rest_1 = require("@octokit/rest");
23-
const node_fetch_1 = __importStar(require("node-fetch"));
24-
run();
25-
async function run() {
26-
const o = new rest_1.Octokit({ auth: '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' });
-
// const { data } = await o.request("/user");
28-
// console.log(data)
29-
const sha = 'fd3d6b191cf773f68ca6dfc57bc52e28513fd8d1';
30-
// const q = `repo:shiftcode/sc-commons next`
31-
// const q = `hash:${sha} repo:shiftcode/sc-commons rev:@*refs/heads/* type:diff`
32-
// const q = `repo:shiftcode/sc-commons@${sha} type:diff`
33-
// const q = `hash:${sha} rev:@*refs/heads/*`
34-
const q = `hash:${sha} repo:shiftcode/sc-commons rev:@refs/heads/#102-fix-peer-deps-version type:diff`;
35-
console.info(`q: ${q}`);
23+
const https = __importStar(require("https"));
24+
const token = process.env.GH_TOKEN;
25+
console.log(token);
26+
const sha = 'fd3d6b191cf773f68ca6dfc57bc52e28513fd8d1';
27+
runWithOctokit()
28+
.then(() => runOther());
29+
async function runWithOctokit() {
30+
console.log(`### execution with octokit client`);
31+
const o = new rest_1.Octokit({ auth: token });
32+
const { data } = await o.request('/user');
33+
console.log(`current user: ${data.login}`);
34+
// query try out
35+
/*
36+
const q = `repo:shiftcode/sc-commons next`
37+
const q = `hash:${sha} repo:shiftcode/sc-commons rev:@*refs/heads/* type:diff`
38+
const q = `repo:shiftcode/sc-commons@${sha} type:diff`
39+
const q = `hash:${sha} rev:@*refs/heads/*`
40+
*/
41+
const q = `hash:${sha} repo:shiftcode/sc-commons rev:@refs/heads/#102-fix-peer-deps-version`;
42+
console.info(`execute with search query: ${q}`);
3643
const response = await o.rest.search.commits({ q });
37-
console.log(response);
44+
// seems like octokit will only return commits from default branch
45+
console.log(`found ${response.data.total_count} commits for sha ${sha}`);
3846
for (const { commit } of response.data.items) {
3947
console.log(`----------------- ${commit.url} -----------------`);
4048
console.log(commit.message);
4149
console.log('-------------------------------------------------');
4250
}
43-
const headers = new node_fetch_1.Headers();
44-
headers.set('Authorization', 'token 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');
45-
const response2 = await (0, node_fetch_1.default)(`https://api.github.com/repos/shiftcode/sc-commons/git/commits/${sha}`, {
46-
headers
51+
}
52+
async function runOther() {
53+
console.log(`### execution with plain http request`);
54+
const url = `https://api.github.com/repos/shiftcode/sc-commons/git/commits/${sha}`;
55+
console.log(url);
56+
const commit = (await fetch(url)); /* and others */
57+
console.log(`----------------- ${commit.url} -----------------`);
58+
console.log(commit.message);
59+
console.log('-------------------------------------------------');
60+
}
61+
async function fetch(url) {
62+
return new Promise((resolve) => {
63+
https.get(url, {
64+
headers: {
65+
Authorization: `token ${token}`,
66+
'User-Agent': 'Github Skip Action',
67+
},
68+
}, res => {
69+
let data = '';
70+
res.on('data', chunk => {
71+
data += chunk;
72+
});
73+
res.on('end', () => {
74+
resolve(JSON.parse(data));
75+
});
76+
});
4777
});
48-
console.log(response2.status);
49-
console.log(await response2.json());
5078
}

package-lock.json

Lines changed: 0 additions & 131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
"@types/node": "^16.0.0",
2626
"typescript": "^4.5.4",
2727
"@octokit/core": "^3.5.1",
28-
"@octokit/rest": "^18.12.0",
29-
"node-fetch": "^2.6.6",
30-
"@types/node-fetch": "^2.5.12"
28+
"@octokit/rest": "^18.12.0"
3129
}
3230
}

0 commit comments

Comments
 (0)
0