Merge pull request #9 from wu-cl/master

feat: add token in api request header for private repos
This commit is contained in:
Adrian Smijulj 2023-04-17 08:40:56 +02:00 committed by GitHub
commit 8b3a60d2b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21126 additions and 16497 deletions

View file

@ -24,4 +24,7 @@ jobs:
- uses: actions/checkout@v2
- 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"
description: "Ensures that all commit messages are following the conventional-commits standard."
inputs:
GITHUB_TOKEN:
description: 'GitHub token'
required: false
runs:
using: node16
main: dist/main/index.js

37341
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;
};
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".
const pushCommits = Array.isArray(get(context, "payload.commits"));
if (pushCommits) {
@ -16,8 +16,15 @@ const extractCommits = async (context): Promise<Commit[]> => {
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,
});
if (Array.isArray(body)) {

View file

@ -9,7 +9,7 @@ async function run() {
` 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) {
core.info(`No commits to check, skipping...`);
return;