mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-08 10:01:34 +00:00
Upgrade all the things
This commit is contained in:
parent
e55b1ed57a
commit
2c495ec569
4 changed files with 2338 additions and 8721 deletions
|
@ -1,6 +1,6 @@
|
|||
import * as jsyaml from 'js-yaml'
|
||||
import micromatch from 'micromatch'
|
||||
import {File, ChangeStatus} from './file'
|
||||
import {File} from './file'
|
||||
|
||||
// Type definition of object we expect to load from YAML
|
||||
interface FilterYaml {
|
||||
|
@ -15,13 +15,6 @@ const MatchOptions: micromatch.Options = {
|
|||
dot: true
|
||||
}
|
||||
|
||||
// Internal representation of one item in named filter rule
|
||||
// Created as simplified form of data in FilterItemYaml
|
||||
interface FilterRuleItem {
|
||||
/** returns the list of matched files */
|
||||
matcher: (files: string[]) => string[]
|
||||
}
|
||||
|
||||
export interface FilterResults {
|
||||
[key: string]: File[]
|
||||
}
|
||||
|
@ -42,7 +35,7 @@ export class Filter {
|
|||
return
|
||||
}
|
||||
|
||||
const doc = jsyaml.safeLoad(yaml) as FilterYaml
|
||||
const doc = jsyaml.load(yaml) as FilterYaml
|
||||
if (typeof doc !== 'object') {
|
||||
this.throwInvalidFormatError('Root element is not an object')
|
||||
}
|
||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -1,7 +1,7 @@
|
|||
import * as fs from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {Webhooks} from '@octokit/webhooks'
|
||||
import {PullRequest, PushEvent} from '@octokit/webhooks-types'
|
||||
|
||||
import {Filter, FilterResults} from './filter'
|
||||
import {File, ChangeStatus} from './file'
|
||||
|
@ -77,7 +77,7 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
|
|||
if (base) {
|
||||
core.warning(`'base' input parameter is ignored when action is triggered by pull request event`)
|
||||
}
|
||||
const pr = github.context.payload.pull_request as Webhooks.WebhookPayloadPullRequestPullRequest
|
||||
const pr = github.context.payload.pull_request as PullRequest
|
||||
if (token) {
|
||||
return await getChangedFilesFromApi(token, pr)
|
||||
}
|
||||
|
@ -97,8 +97,7 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
|
|||
async function getChangedFilesFromGit(base: string, head: string, initialFetchDepth: number): Promise<File[]> {
|
||||
const defaultBranch = github.context.payload.repository?.default_branch
|
||||
|
||||
const beforeSha =
|
||||
github.context.eventName === 'push' ? (github.context.payload as Webhooks.WebhookPayloadPush).before : null
|
||||
const beforeSha = github.context.eventName === 'push' ? (github.context.payload as PushEvent).before : null
|
||||
|
||||
const currentRef = await git.getCurrentRef()
|
||||
|
||||
|
@ -158,13 +157,10 @@ async function getChangedFilesFromGit(base: string, head: string, initialFetchDe
|
|||
}
|
||||
|
||||
// Uses github REST api to get list of files changed in PR
|
||||
async function getChangedFilesFromApi(
|
||||
token: string,
|
||||
prNumber: Webhooks.WebhookPayloadPullRequestPullRequest
|
||||
): Promise<File[]> {
|
||||
async function getChangedFilesFromApi(token: string, prNumber: PullRequest): Promise<File[]> {
|
||||
core.startGroup(`Fetching list of changed files for PR#${prNumber.number} from Github API`)
|
||||
try {
|
||||
const client = new github.GitHub(token)
|
||||
const client = github.getOctokit(token).rest
|
||||
const per_page = 100
|
||||
const files: File[] = []
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue