Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Florent Poinsard 2022-10-26 15:40:33 +02:00
commit 245527a2ef
12 changed files with 49242 additions and 44789 deletions

View file

@ -1,21 +0,0 @@
import {exec as execImpl, ExecOptions} from '@actions/exec'
// Wraps original exec() function
// Returns exit code and whole stdout/stderr
export default async function exec(commandLine: string, args?: string[], options?: ExecOptions): Promise<ExecResult> {
options = options || {}
let stdout = ''
let stderr = ''
options.listeners = {
stdout: (data: Buffer) => (stdout += data.toString()),
stderr: (data: Buffer) => (stderr += data.toString())
}
const code = await execImpl(commandLine, args, options)
return {code, stdout, stderr}
}
export interface ExecResult {
code: number
stdout: string
stderr: string
}

View file

@ -1,4 +1,4 @@
import exec from './exec'
import {getExecOutput} from '@actions/exec'
import * as core from '@actions/core'
import {File, ChangeStatus} from './file'
@ -9,7 +9,7 @@ export async function getChangesInLastCommit(): Promise<File[]> {
core.startGroup(`Change detection in last commit`)
let output = ''
try {
output = (await exec('git', ['log', '--format=', '--no-renames', '--name-status', '-z', '-n', '1'])).stdout
output = (await getExecOutput('git', ['log', '--format=', '--no-renames', '--name-status', '-z', '-n', '1'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
@ -27,7 +27,8 @@ export async function getChanges(base: string, head: string): Promise<File[]> {
let output = ''
try {
// Two dots '..' change detection - directly compares two versions
output = (await exec('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef}..${headRef}`])).stdout
output = (await getExecOutput('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef}..${headRef}`]))
.stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
@ -41,7 +42,7 @@ export async function getChangesOnHead(): Promise<File[]> {
core.startGroup(`Change detection on HEAD`)
let output = ''
try {
output = (await exec('git', ['diff', '--no-renames', '--name-status', '-z', 'HEAD'])).stdout
output = (await getExecOutput('git', ['diff', '--no-renames', '--name-status', '-z', 'HEAD'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
@ -57,7 +58,7 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
if (baseRef === undefined || headRef === undefined) {
return false
}
return (await exec('git', ['merge-base', baseRef, headRef], {ignoreReturnCode: true})).code === 0
return (await getExecOutput('git', ['merge-base', baseRef, headRef], {ignoreReturnCode: true})).exitCode === 0
}
let noMergeBase = false
@ -66,12 +67,12 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
baseRef = await getLocalRef(base)
headRef = await getLocalRef(head)
if (!(await hasMergeBase())) {
await exec('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, head])
await getExecOutput('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, head])
if (baseRef === undefined || headRef === undefined) {
baseRef = baseRef ?? (await getLocalRef(base))
headRef = headRef ?? (await getLocalRef(head))
if (baseRef === undefined || headRef === undefined) {
await exec('git', ['fetch', '--tags', '--depth=1', 'origin', base, head], {
await getExecOutput('git', ['fetch', '--tags', '--depth=1', 'origin', base, head], {
ignoreReturnCode: true // returns exit code 1 if tags on remote were updated - we can safely ignore it
})
baseRef = baseRef ?? (await getLocalRef(base))
@ -93,12 +94,12 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
let lastCommitCount = await getCommitCount()
while (!(await hasMergeBase())) {
depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER)
await exec('git', ['fetch', `--deepen=${depth}`, 'origin', base, head])
await getExecOutput('git', ['fetch', `--deepen=${depth}`, 'origin', base, head])
const commitCount = await getCommitCount()
if (commitCount === lastCommitCount) {
core.info('No more commits were fetched')
core.info('Last attempt will be to fetch full history')
await exec('git', ['fetch'])
await getExecOutput('git', ['fetch'])
if (!(await hasMergeBase())) {
noMergeBase = true
}
@ -122,7 +123,7 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
core.startGroup(`Change detection ${diffArg}`)
let output = ''
try {
output = (await exec('git', ['diff', '--no-renames', '--name-status', '-z', diffArg])).stdout
output = (await getExecOutput('git', ['diff', '--no-renames', '--name-status', '-z', diffArg])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
@ -147,7 +148,7 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
core.startGroup('Listing all files tracked by git')
let output = ''
try {
output = (await exec('git', ['ls-files', '-z'])).stdout
output = (await getExecOutput('git', ['ls-files', '-z'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
@ -165,17 +166,17 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
export async function getCurrentRef(): Promise<string> {
core.startGroup(`Get current git ref`)
try {
const branch = (await exec('git', ['branch', '--show-current'])).stdout.trim()
const branch = (await getExecOutput('git', ['branch', '--show-current'])).stdout.trim()
if (branch) {
return branch
}
const describe = await exec('git', ['describe', '--tags', '--exact-match'], {ignoreReturnCode: true})
if (describe.code === 0) {
const describe = await getExecOutput('git', ['describe', '--tags', '--exact-match'], {ignoreReturnCode: true})
if (describe.exitCode === 0) {
return describe.stdout.trim()
}
return (await exec('git', ['rev-parse', HEAD])).stdout.trim()
return (await getExecOutput('git', ['rev-parse', HEAD])).stdout.trim()
} finally {
core.endGroup()
}
@ -198,11 +199,11 @@ export function isGitSha(ref: string): boolean {
}
async function hasCommit(ref: string): Promise<boolean> {
return (await exec('git', ['cat-file', '-e', `${ref}^{commit}`], {ignoreReturnCode: true})).code === 0
return (await getExecOutput('git', ['cat-file', '-e', `${ref}^{commit}`], {ignoreReturnCode: true})).exitCode === 0
}
async function getCommitCount(): Promise<number> {
const output = (await exec('git', ['rev-list', '--count', '--all'])).stdout
const output = (await getExecOutput('git', ['rev-list', '--count', '--all'])).stdout
const count = parseInt(output)
return isNaN(count) ? 0 : count
}
@ -212,7 +213,7 @@ async function getLocalRef(shortName: string): Promise<string | undefined> {
return (await hasCommit(shortName)) ? shortName : undefined
}
const output = (await exec('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout
const output = (await getExecOutput('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout
const refs = output
.split(/\r?\n/g)
.map(l => l.match(/refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/))
@ -236,10 +237,10 @@ async function ensureRefAvailable(name: string): Promise<string> {
try {
let ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--no-tags', 'origin', name])
await getExecOutput('git', ['fetch', '--depth=1', '--no-tags', 'origin', name])
ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--tags', 'origin', name])
await getExecOutput('git', ['fetch', '--depth=1', '--tags', 'origin', name])
ref = await getLocalRef(name)
if (ref === undefined) {
throw new Error(`Could not determine what is ${name} - fetch works but it's not a branch, tag or commit SHA`)

View file

@ -1,6 +1,7 @@
import * as fs from 'fs'
import * as core from '@actions/core'
import * as github from '@actions/github'
import type {Octokit} from '@octokit/rest'
import {Webhooks} from '@octokit/webhooks'
import {Filter, FilterResults} from './filter'
@ -170,25 +171,19 @@ async function getChangedFilesFromApi(
const per_page = 100
const files: File[] = []
for (let page = 1; ; page++) {
core.info(`Invoking listFiles(pull_number: ${prNumber.number}, page: ${page}, per_page: ${per_page})`)
const response = await client.pulls.listFiles({
core.info(`Invoking listFiles(pull_number: ${prNumber.number}, per_page: ${per_page})`)
for await (const response of client.paginate.iterator(
client.pulls.listFiles.endpoint.merge({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber.number,
per_page,
page
per_page
})
) as AsyncIterableIterator<Octokit.Response<Octokit.PullsListFilesResponse>>) {
if (response.status !== 200) {
throw new Error(`Fetching list of changed files from GitHub API failed with error code ${response.status}`)
}
core.info(`Received ${response.data.length} items`)
if (response.data.length === 0) {
core.info('All changed files has been fetched from GitHub API')
break
}
for (const row of response.data) {
core.info(`[${row.status}] ${row.filename}`)