11// GitHub support utility.
22
33import { resolve } from "path"
4- import { GitHub } from "@actions/github/lib/utils" ;
5- import * as github from "@actions/github" ;
6- import * as core from "@actions/core" ;
7- import fs from "fs" ;
8- import { Commit } from "./commit" ;
9- import { Result , Status } from "./commit-validator" ;
10- import { pathToFileURL } from "url" ;
4+ import { GitHub } from "@actions/github/lib/utils"
5+ import * as github from "@actions/github"
6+ import * as core from "@actions/core"
7+ import fs from "fs"
8+ import { Commit } from "./commit"
9+ import { Result , Status } from "./commit-validator"
10+ import { pathToFileURL } from "url"
1111
1212// return html url to validator file and local filepath to downloaded file
13- export async function download_validator_file ( validator_file : string , octokit : InstanceType < typeof GitHub > ) : Promise < [ string , string ] > {
13+ export async function download_validator_file (
14+ validator_file : string ,
15+ octokit : InstanceType < typeof GitHub >
16+ ) : Promise < [ string , string ] > {
1417 const response = await octokit . rest . repos . getContent ( {
1518 path : validator_file ,
1619 owner : github . context . repo . owner ,
1720 repo : github . context . repo . repo ,
18- ref : github . context . sha ,
21+ ref : github . context . sha
1922 } )
2023 if ( response . status !== 200 ) {
2124 core . error ( JSON . stringify ( response . data ) )
@@ -30,17 +33,17 @@ export async function download_validator_file(validator_file: string, octokit: I
3033 core . setFailed ( `download of '${ response . url } ' failed` )
3134 return [ "" , "" ]
3235 }
33- const buffer = Buffer . from ( response . data . content , ' base64' ) . toString ( ' utf-8' )
36+ const buffer = Buffer . from ( response . data . content , " base64" ) . toString ( " utf-8" )
3437 const output_path = pathToFileURL ( resolve ( "./validator.mjs" ) )
3538 fs . writeFileSync ( output_path , buffer )
3639 return [ response . data . html_url || "" , output_path . toString ( ) ]
3740}
3841
3942export async function get_commit_creation ( octokit : InstanceType < typeof GitHub > ) : Promise < string > {
40- const response = await octokit . request ( ' GET /repos/{owner}/{repo}/git/commits/{commit_sha}' , {
43+ const response = await octokit . request ( " GET /repos/{owner}/{repo}/git/commits/{commit_sha}" , {
4144 owner : github . context . repo . owner ,
4245 repo : github . context . repo . repo ,
43- commit_sha : github . context . payload . pull_request ?. base . sha ,
46+ commit_sha : github . context . payload . pull_request ?. base . sha
4447 } )
4548 if ( response . status !== 200 ) {
4649 core . error ( JSON . stringify ( response . data ) )
@@ -55,16 +58,16 @@ export async function get_commit_creation(octokit: InstanceType<typeof GitHub>):
5558export async function get_commits ( octokit : InstanceType < typeof GitHub > ) : Promise < Commit [ ] > {
5659 const commits : Commit [ ] = [ ]
5760 switch ( github . context . eventName ) {
58- case ' pull_request' : {
61+ case " pull_request" : {
5962 const pages = Math . floor ( github . context . payload . pull_request ?. commits / 100 ) + 1
6063 for ( let page = 1 ; page <= pages ; page ++ ) {
61- const response = await octokit . request ( ' GET /repos/{owner}/{repo}/commits' , {
64+ const response = await octokit . request ( " GET /repos/{owner}/{repo}/commits" , {
6265 owner : github . context . payload . pull_request ?. head . repo . owner . login ,
6366 repo : github . context . payload . pull_request ?. head . repo . name ,
6467 sha : github . context . payload . pull_request ?. head . ref ,
6568 since : await get_commit_creation ( octokit ) ,
6669 per_page : 100 ,
67- page,
70+ page
6871 } )
6972 if ( response . status !== 200 ) {
7073 core . error ( JSON . stringify ( response . data ) )
@@ -80,15 +83,15 @@ export async function get_commits(octokit: InstanceType<typeof GitHub>): Promise
8083 }
8184 break
8285 }
83- case ' push' :
86+ case " push" :
8487 default : {
85- if ( ' commits' in github . context . payload && github . context . payload [ ' commits' ] . length > 0 ) {
86- for ( const commit of github . context . payload [ ' commits' ] ) {
88+ if ( " commits" in github . context . payload && github . context . payload [ " commits" ] . length > 0 ) {
89+ for ( const commit of github . context . payload [ " commits" ] ) {
8790 commits . push ( new Commit ( commit ) )
8891 }
8992 // on tags or if commits was empty
90- } else if ( ' head_commit' in github . context . payload ) {
91- commits . push ( new Commit ( github . context . payload [ ' head_commit' ] ) )
93+ } else if ( " head_commit" in github . context . payload ) {
94+ commits . push ( new Commit ( github . context . payload [ " head_commit" ] ) )
9295 }
9396 }
9497 }
0 commit comments