Merge pull request #2 from dkhunt27/prev

updated package versions; added some additional logging
This commit is contained in:
Dan Hunt 2024-01-26 10:40:43 -05:00 committed by GitHub
commit b4fec2d1ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12715 additions and 25285 deletions

28716
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

9219
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -6,18 +6,17 @@
"author": "Adrian Smijulj <adrian1358@gmail.com>",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3",
"@actions/github": "^2.1.1",
"got": "^11.3.0",
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"got": "^11.8.6",
"lodash.get": "^4.4.2"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1",
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@babel/preset-typescript": "^7.10.1",
"@types/jest": "^26.0.0",
"@vercel/ncc": "^0.38.1",
"babel-jest": "^26.0.1",
"jest": "^26.0.1",
"prettier": "^2.0.2",

View file

@ -6,33 +6,51 @@ type Commit = {
};
const extractCommits = async (context, core): Promise<Commit[]> => {
core.debug(`context.payload.commits: ${JSON.stringify(context.payload.commits, null, 2)}\n`);
core.debug(`context.payload.pull_request: ${JSON.stringify(context.payload.pull_request, null, 2)}\n`);
// For "push" events, commits can be found in the "context.payload.commits".
const pushCommits = Array.isArray(get(context, "payload.commits"));
if (pushCommits) {
core.info(`detected a "push"; using those commits`);
return context.payload.commits;
}
// For PRs, we need to get a list of commits via the GH API:
const prCommitsUrl = get(context, "payload.pull_request.commits_url");
if (prCommitsUrl) {
try {
let requestHeaders = {
"Accept": "application/vnd.github+json",
}
if (core.getInput('GITHUB_TOKEN') != "") {
requestHeaders["Authorization"] = "token " + core.getInput('GITHUB_TOKEN')
}
const { body } = await got.get(prCommitsUrl, {
responseType: "json",
headers: requestHeaders,
});
const pull_request = get(context, "payload.pull_request");
if (!pull_request) {
core.warnMsg("Push or Pull Request not detected; no commits to check");
} else {
core.info(`detected a "pull request"; using those commits`);
if (Array.isArray(body)) {
return body.map((item) => item.commit);
const prCommitsUrl = get(pull_request, "commits_url");
if (prCommitsUrl) {
try {
let requestHeaders = {
"Accept": "application/vnd.github+json",
}
if (core.getInput('GITHUB_TOKEN') != "") {
requestHeaders["Authorization"] = "token " + core.getInput('GITHUB_TOKEN')
}
const { body } = await got.get(prCommitsUrl, {
responseType: "json",
headers: requestHeaders,
});
core.debug(`body extracted: ${JSON.stringify(body)}`);
core.info(`Commits extracted: ${(body as any)?.length}`);
if (Array.isArray(body)) {
return body.map((item) => item.commit);
}
return [];
} catch (err) {
const msg = (err as any)?.message || err;
core.warnMsg(`Issue processing prCommitsUrl: ${msg}; no commits to check`);
return [];
}
return [];
} catch {
return [];
} else {
core.warnMsg("missing prCommitsUrl; no commits to check");
}
}