Skip to content

Commit

Permalink
Merge pull request #5 from platinummonkey/bump-node
Browse files Browse the repository at this point in the history
bump node version
  • Loading branch information
platinummonkey authored Aug 2, 2023
2 parents ea28c19 + a589433 commit 28f3f95
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 110 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'build-test'
name: 'test'
on: # rebuild any PRs and main branch changes
pull_request:

Expand All @@ -7,7 +7,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
- name: changed-files
id: changed-files
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
separator: ','
- name: output results
shell: bash
env:
OUTPUT_ANY_CHANGED: ${{ steps.changed-files.outputs.any_changed }}
OUTPUT_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
OUTPUT_ANY_ADDED: ${{ steps.changed-files.outputs.any_added }}
OUTPUT_ANY_MODIFIED: ${{ steps.changed-files.outputs.any_modified }}
OUTPUT_ANY_DELETED: ${{ steps.changed-files.outputs.any_deleted }}
OUTPUT_ONLY_ADDED_FILES: ${{ steps.changed-files.outputs.only_added }}
OUTPUT_ONLY_MODIFIED_FILES: ${{ steps.changed-files.outputs.only_modified }}
OUTPUT_ONLY_DELETED_FILES: ${{ steps.changed-files.outputs.only_deleted }}
run: |
echo "any_changed=${OUTPUT_ANY_CHANGED}"
echo "all_changed_files=${OUTPUT_ALL_CHANGED_FILES}"
echo "any_added=${OUTPUT_ANY_ADDED}"
echo "any_modified=${OUTPUT_ANY_MODIFIED}"
echo "any_deleted=${OUTPUT_ANY_DELETED}"
echo "only_added=${OUTPUT_ONLY_ADDED_FILES}"
echo "only_modified=${OUTPUT_ONLY_MODIFIED_FILES}"
echo "only_deleted=${OUTPUT_ONLY_DELETED_FILES}"
96 changes: 50 additions & 46 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@actions/github": "^5.1.1"
},
"devDependencies": {
"@types/node": "^18.16.3",
"@types/node": "^20.4.5",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.0.0",
"@vercel/ncc": "^0.36.1",
Expand Down
55 changes: 0 additions & 55 deletions src/changed-files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import {Context} from '@actions/github/lib/context'
import {Api} from '@octokit/plugin-rest-endpoint-methods/dist-types/types' // eslint-disable-line

export class FileMod {
filename: string
status: string // added,removed,modified,renamed,copied,changed,unchanged
Expand Down Expand Up @@ -79,55 +76,3 @@ export async function changedFiles(
resolve(results)
})
}

export async function getDiffPaths(gh: Api, ctx: Context): Promise<FileMod[]> {
return new Promise(async resolve => {
if (ctx.payload.pull_request === undefined) {
throw new Error('missing payload pull request context')
}

const prMetadata = {
owner: ctx.repo.owner,
repo: ctx.repo.repo,
pull_number: ctx.payload.pull_request.number
}

/**
* `data` is an array of items that look like this:
* {
*
* filename: 'foo/bar/baz.json',
* status: 'modified', // added,removed,modified,renamed,copied,changed,unchanged
* additions: 14,
* deletions: 14,
* changes: 14,
* blob_url: "..."
* contents_url: "...",
* raw_url: "...",
* patch: '@@ -1,2 +1,2 @@\n' +
* ' "foo": "bar",\n' +
* '-"hello": "world"\n' +
* '+"hello": "people"'
* }
*
*
* listFiles(params?: (RequestParameters & Omit<{ owner: string; repo: string; pull_number: number; } & { per_page?: number | undefined; page?: number | undefined; }, "baseUrl" | "headers" | "mediaType">) | undefined):
* Promise<OctokitResponse<{ sha: string; filename: string; status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged"; additions: number; deletions: number; changes: number; blob_url: string; raw_url: string; contents_url: string; patch?: string | undefined; previous_filename?: string | undefined; }[], 200>>
*
*/
const {data} = await gh.rest.pulls.listFiles(prMetadata)

const diffPaths: FileMod[] = data.map((item: any) => {
// eslint-disable-line
return new FileMod(
item.filename,
item.status,
item.additions,
item.deletions,
item.patch
)
})

resolve(diffPaths)
})
}
61 changes: 60 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {Context} from '@actions/github/lib/context'
import {Api} from '@octokit/plugin-rest-endpoint-methods/dist-types/types' // eslint-disable-line
import {
FileMod,
changedFiles,
getDiffPaths,
fileModsToPaths,
fileModsByStatus
} from './changed-files'
Expand All @@ -15,7 +16,13 @@ async function run(): Promise<void> {
trimWhitespace: true
})
const gh = github.getOctokit(ghToken)

core.debug(
`repo_owner=${github.context.repo.owner} repo=${github.context.repo} pull_number=${github.context.payload.pull_request?.number}`
)

const allChangedFiles: FileMod[] = await getDiffPaths(gh, github.context)
core.debug(`all_changed_files=${allChangedFiles}`)

const separator: string = core.getInput('separator', {
required: true,
Expand Down Expand Up @@ -95,4 +102,56 @@ async function run(): Promise<void> {
}
}

export async function getDiffPaths(gh: Api, ctx: Context): Promise<FileMod[]> {
return new Promise(async resolve => {
if (ctx.payload.pull_request === undefined) {
throw new Error('missing payload pull request context')
}

const prMetadata = {
owner: ctx.repo.owner,
repo: ctx.repo.repo,
pull_number: ctx.payload.pull_request.number
}

/**
* `data` is an array of items that look like this:
* {
*
* filename: 'foo/bar/baz.json',
* status: 'modified', // added,removed,modified,renamed,copied,changed,unchanged
* additions: 14,
* deletions: 14,
* changes: 14,
* blob_url: "..."
* contents_url: "...",
* raw_url: "...",
* patch: '@@ -1,2 +1,2 @@\n' +
* ' "foo": "bar",\n' +
* '-"hello": "world"\n' +
* '+"hello": "people"'
* }
*
*
* listFiles(params?: (RequestParameters & Omit<{ owner: string; repo: string; pull_number: number; } & { per_page?: number | undefined; page?: number | undefined; }, "baseUrl" | "headers" | "mediaType">) | undefined):
* Promise<OctokitResponse<{ sha: string; filename: string; status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged"; additions: number; deletions: number; changes: number; blob_url: string; raw_url: string; contents_url: string; patch?: string | undefined; previous_filename?: string | undefined; }[], 200>>
*
*/
const {data} = await gh.rest.pulls.listFiles(prMetadata)

const diffPaths: FileMod[] = data.map((item: any) => {
// eslint-disable-line
return new FileMod(
item.filename,
item.status,
item.additions,
item.deletions,
item.patch
)
})

resolve(diffPaths)
})
}

run()

0 comments on commit 28f3f95

Please sign in to comment.