Skip to content

Commit

Permalink
More helpful errors for config file not found
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Aug 6, 2021
1 parent 43650f0 commit 417a804
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
File renamed without changes.
9 changes: 7 additions & 2 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Component Owners'
name: 'Auto Assign'
on:
pull_request:

Expand All @@ -7,4 +7,9 @@ jobs:
runs-on: ubuntu-latest
name: Auto Assign Owners
steps:
- uses: dyladan/component-owners@main
# To use this repository's private action,
# you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Self action step
uses: ./ # Uses an action in the root directory
16 changes: 10 additions & 6 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.

7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import { getChangedFiles, getConfig, getOwners, getPullAuthor, getRefs, getColla
async function main() {
const client = github.getOctokit(core.getInput('repo-token', { required: true }));
const ownerFilePath = core.getInput('config-file', { required: true });

const assignOwners = core.getBooleanInput('assign-owners', { required: true })
const requestOwnerReviews = core.getBooleanInput('request-owner-reviews', { required: true })

const { base, head } = getRefs();

// Log the base and head commits
core.info(`Base commit: ${base}`)
core.info(`Head commit: ${head}`)

const config = await getConfig(client, head, ownerFilePath);

const changedFiles = await getChangedFiles(client, base, head);
const owners = await getOwners(config, changedFiles);


core.info(`${owners.length} owners found ${owners.join(" ")}`);

if (assignOwners && owners.length > 0) {
Expand Down
12 changes: 6 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ export function getRefs() {
)
}

// Log the base and head commits
core.info(`Base commit: ${base}`)
core.info(`Head commit: ${head}`)

// Ensure that the base and head properties are set on the payload.
if (!base || !head) {
throw new Error(
Expand Down Expand Up @@ -164,8 +160,12 @@ export async function getChangedFiles(client: Client, base: string, head: string


export async function getConfig(client: Client, ref: string, location: string): Promise<Config> {
const contents = await getFileContents(client, ref, location);
return yaml.load(contents, { filename: location }) as any;
try {
const contents = await getFileContents(client, ref, location);
return yaml.load(contents, { filename: location }) as any;
} catch (err) {
throw new Error(`Failed to get configuration ${ref.slice(0, 7)} ${err.message} ${location}`)
}
}

async function getFileContents(client: Client, ref: string, location: string): Promise<string> {
Expand Down

0 comments on commit 417a804

Please sign in to comment.