feat: add token in api request header for private repos

This commit is contained in:
Changliang Wu 2023-04-13 11:48:03 +08:00
parent 679da979e4
commit c12108d422
No known key found for this signature in database
GPG key ID: 45D7CA7699EDE780
5 changed files with 21126 additions and 16497 deletions

View file

@ -24,4 +24,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: webiny/action-conventional-commits@v1.1.0 - uses: webiny/action-conventional-commits@v1.1.0
# optional, required for private repos
# with:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```

View file

@ -1,5 +1,9 @@
name: "Conventional Commits" name: "Conventional Commits"
description: "Ensures that all commit messages are following the conventional-commits standard." description: "Ensures that all commit messages are following the conventional-commits standard."
inputs:
GITHUB_TOKEN:
description: 'GitHub token'
required: false
runs: runs:
using: node16 using: node16
main: dist/main/index.js main: dist/main/index.js

37597
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -5,7 +5,7 @@ type Commit = {
message: string; message: string;
}; };
const extractCommits = async (context): Promise<Commit[]> => { const extractCommits = async (context, core): Promise<Commit[]> => {
// For "push" events, commits can be found in the "context.payload.commits". // For "push" events, commits can be found in the "context.payload.commits".
const pushCommits = Array.isArray(get(context, "payload.commits")); const pushCommits = Array.isArray(get(context, "payload.commits"));
if (pushCommits) { if (pushCommits) {
@ -16,8 +16,15 @@ const extractCommits = async (context): Promise<Commit[]> => {
const prCommitsUrl = get(context, "payload.pull_request.commits_url"); const prCommitsUrl = get(context, "payload.pull_request.commits_url");
if (prCommitsUrl) { if (prCommitsUrl) {
try { 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, { const { body } = await got.get(prCommitsUrl, {
responseType: "json", responseType: "json",
headers: requestHeaders,
}); });
if (Array.isArray(body)) { if (Array.isArray(body)) {

View file

@ -9,7 +9,7 @@ async function run() {
` Checking if commit messages are following the Conventional Commits specification...` ` Checking if commit messages are following the Conventional Commits specification...`
); );
const extractedCommits = await extractCommits(context); const extractedCommits = await extractCommits(context, core);
if (extractedCommits.length === 0) { if (extractedCommits.length === 0) {
core.info(`No commits to check, skipping...`); core.info(`No commits to check, skipping...`);
return; return;