Skip to content

Commit

Permalink
run fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Rui Chen <rui@chenrui.dev>
  • Loading branch information
chenrui333 committed Jul 18, 2024
1 parent 75e098c commit ee91720
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
34 changes: 17 additions & 17 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe("util", () => {
it("strips template", () => {
assert.equal(
uploadUrl(
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}"
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
),
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets"
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets",
);
});
});
Expand All @@ -30,7 +30,7 @@ describe("util", () => {
it("parses newline and comma-delimited (and then some)", () => {
assert.deepStrictEqual(
parseInputFiles("foo,bar\nbaz,boom,\n\ndoom,loom "),
["foo", "bar", "baz", "boom", "doom", "loom"]
["foo", "bar", "baz", "boom", "doom", "loom"],
);
});
});
Expand All @@ -53,7 +53,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
})
}),
);
});
it("uses input body path", () => {
Expand All @@ -74,7 +74,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
})
}),
);
});
it("defaults to body path when both body and body path are provided", () => {
Expand All @@ -95,7 +95,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
})
}),
);
});
});
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});

Expand All @@ -155,7 +155,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});
it("supports discussion category names", () => {
Expand All @@ -180,7 +180,7 @@ describe("util", () => {
input_discussion_category_name: "releases",
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});

Expand All @@ -206,7 +206,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: true,
input_make_latest: undefined,
}
},
);
});

Expand Down Expand Up @@ -235,7 +235,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});
it("uses input token as the source of GITHUB_TOKEN by default", () => {
Expand All @@ -262,7 +262,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});
it("parses basic config with draft and prerelease", () => {
Expand All @@ -288,7 +288,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});
it("parses basic config where make_latest is passed", () => {
Expand All @@ -313,7 +313,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: "false",
}
},
);
});
it("parses basic config with append_body", () => {
Expand All @@ -338,7 +338,7 @@ describe("util", () => {
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}
},
);
});
});
Expand All @@ -355,7 +355,7 @@ describe("util", () => {
it("resolves files given a set of paths", async () => {
assert.deepStrictEqual(
paths(["tests/data/**/*", "tests/data/does/not/exist/*"]),
["tests/data/foo/bar.txt"]
["tests/data/foo/bar.txt"],
);
});
});
Expand All @@ -364,7 +364,7 @@ describe("util", () => {
it("returns the patterns that don't match any files", async () => {
assert.deepStrictEqual(
unmatchedPatterns(["tests/data/**/*", "tests/data/does/not/exist/*"]),
["tests/data/does/not/exist/*"]
["tests/data/does/not/exist/*"],
);
});
});
Expand Down
26 changes: 13 additions & 13 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class GitHubReleaser implements Releaser {
}): AsyncIterableIterator<{ data: Release[] }> {
const updatedParams = { per_page: 100, ...params };
return this.github.paginate.iterator(
this.github.rest.repos.listReleases.endpoint.merge(updatedParams)
this.github.rest.repos.listReleases.endpoint.merge(updatedParams),
);
}
}
Expand All @@ -144,15 +144,15 @@ export const upload = async (
github: GitHub,
url: string,
path: string,
currentAssets: Array<{ id: number; name: string }>
currentAssets: Array<{ id: number; name: string }>,
): Promise<any> => {
const [owner, repo] = config.github_repository.split("/");
const { name, size, mime, data: body } = asset(path);
const currentAsset = currentAssets.find(
// note: GitHub renames asset filenames that have special characters, non-alphanumeric characters, and leading or trailing periods. The "List release assets" endpoint lists the renamed filenames.
// due to this renaming we need to be mindful when we compare the file name we're uploading with a name github may already have rewritten for logical comparison
// see https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset
({ name: currentName }) => currentName == name.replace(" ", ".")
({ name: currentName }) => currentName == name.replace(" ", "."),
);
if (currentAsset) {
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
Expand Down Expand Up @@ -180,7 +180,7 @@ export const upload = async (
throw new Error(
`Failed to upload release asset ${name}. received status code ${
resp.status
}\n${json.message}\n${JSON.stringify(json.errors)}`
}\n${json.message}\n${JSON.stringify(json.errors)}`,
);
}
return json;
Expand All @@ -189,7 +189,7 @@ export const upload = async (
export const release = async (
config: Config,
releaser: Releaser,
maxRetries: number = 3
maxRetries: number = 3,
): Promise<Release> => {
if (maxRetries <= 0) {
console.log(`❌ Too many retries. Aborting...`);
Expand Down Expand Up @@ -234,13 +234,13 @@ export const release = async (
repo,
discussion_category_name,
generate_release_notes,
maxRetries
maxRetries,
);
}

let existingRelease: Release = _release!;
console.log(
`Found release ${existingRelease.name} (with id=${existingRelease.id})`
`Found release ${existingRelease.name} (with id=${existingRelease.id})`,
);

const release_id = existingRelease.id;
Expand All @@ -250,7 +250,7 @@ export const release = async (
config.input_target_commitish !== existingRelease.target_commitish
) {
console.log(
`Updating commit from "${existingRelease.target_commitish}" to "${config.input_target_commitish}"`
`Updating commit from "${existingRelease.target_commitish}" to "${config.input_target_commitish}"`,
);
target_commitish = config.input_target_commitish;
} else {
Expand Down Expand Up @@ -301,7 +301,7 @@ export const release = async (
} catch (error) {
if (error.status !== 404) {
console.log(
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`,
);
throw error;
}
Expand All @@ -314,7 +314,7 @@ export const release = async (
repo,
discussion_category_name,
generate_release_notes,
maxRetries
maxRetries,
);
}
};
Expand All @@ -327,7 +327,7 @@ async function createRelease(
repo: string,
discussion_category_name: string | undefined,
generate_release_notes: boolean | undefined,
maxRetries: number
maxRetries: number,
) {
const tag_name = tag;
const name = config.input_name || tag;
Expand All @@ -341,7 +341,7 @@ async function createRelease(
commitMessage = ` using commit "${target_commitish}"`;
}
console.log(
`👩‍🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
`👩‍🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`,
);
try {
let release = await releaser.createRelease({
Expand All @@ -366,7 +366,7 @@ async function createRelease(
switch (error.status) {
case 403:
console.log(
"Skip retry — your GitHub token/PAT does not have the required permission to create a release"
"Skip retry — your GitHub token/PAT does not have the required permission to create a release",
);
throw error;

Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function run() {
throttle: {
onRateLimit: (retryAfter, options) => {
console.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
`Request quota exhausted for request ${options.method} ${options.url}`,
);
if (options.request.retryCount === 0) {
// only retries once
Expand All @@ -57,7 +57,7 @@ async function run() {
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
console.warn(
`Abuse detected for request ${options.method} ${options.url}`
`Abuse detected for request ${options.method} ${options.url}`,
);
},
},
Expand All @@ -81,11 +81,11 @@ async function run() {
gh,
uploadUrl(rel.upload_url),
path,
currentAssets
currentAssets,
);
delete json.uploader;
return json;
})
}),
).catch((error) => {
throw error;
});
Expand Down
6 changes: 3 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const parseInputFiles = (files: string): string[] => {
.concat(line.split(","))
.filter((pat) => pat)
.map((pat) => pat.trim()),
[]
[],
);
};

Expand Down Expand Up @@ -80,7 +80,7 @@ export const parseConfig = (env: Env): Config => {
export const paths = (patterns: string[]): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => {
return acc.concat(
glob.sync(pattern).filter((path) => statSync(path).isFile())
glob.sync(pattern).filter((path) => statSync(path).isFile()),
);
}, []);
};
Expand All @@ -90,7 +90,7 @@ export const unmatchedPatterns = (patterns: string[]): string[] => {
return acc.concat(
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0
? [pattern]
: []
: [],
);
}, []);
};
Expand Down

0 comments on commit ee91720

Please sign in to comment.