Skip to content

Commit

Permalink
refactor: add function return types
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Nov 9, 2023
1 parent 6cee247 commit ba4b61e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/octokit.d.ts

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

2 changes: 1 addition & 1 deletion dist/pull-request.js.map

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

2 changes: 1 addition & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CustomOctokit } from './octokit';
import { PullRequest } from './pull-request';
import { Tag } from './tag';

async function action(octokit: CustomOctokit) /*: Promise<string>*/ {
async function action(octokit: CustomOctokit): Promise<void> {
const config = await Config.getConfig(octokit);

const tag = new Tag(await Tag.getLatestTag());
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Config {
return new this(retrievedConfig);
}

static isConfigEmpty(config: unknown) {
static isConfigEmpty(config: unknown): boolean {
return config === null || config === undefined;
}
}
4 changes: 2 additions & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Metadata {
static readonly metadataFreezingTag = 'freezing-tag';
static readonly metadataCommentID = 'comment-id';

async setMetadata() {
async setMetadata(): Promise<void> {
if (this.commentID !== undefined) {
await this.controller.setMetadata(
this.issueNumber,
Expand All @@ -59,7 +59,7 @@ export class Metadata {
);
}

static async getMetadata(issueNumber: number) {
static async getMetadata(issueNumber: number): Promise<Metadata> {
const controller = new MetadataController('devel-freezer', {
...context.repo,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CustomOctokit = Octokit.plugin(config);

export type CustomOctokit = InstanceType<typeof CustomOctokit>;

export function getOctokit(token: string) {
export function getOctokit(token: string): CustomOctokit {
return new CustomOctokit({
auth: token,
});
Expand Down
15 changes: 9 additions & 6 deletions src/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class PullRequest {
return this._metadata;
}

isFreezed() {
isFreezed(): boolean {
return !!this.metadata.commentID && !!this.metadata.tag;
}

isTagPolicyCompliant(tagPolicy: string[], tag?: string) {
isTagPolicyCompliant(tagPolicy: string[], tag?: string): boolean {
debug(`Checking tag policy for PR: #${this.id}`);
const freezingTag = tag ?? this.metadata.tag;
if (freezingTag === undefined) false;
Expand All @@ -33,7 +33,7 @@ export class PullRequest {
);
}

async freeze(content: string, freezingTag: string) {
async freeze(content: string, freezingTag: string): Promise<void> {
debug(`Freezing PR: #${this.id}`);
const id = await this.publishComment(content);

Expand All @@ -42,15 +42,15 @@ export class PullRequest {
await this.metadata.setMetadata();
}

async unfreeze(content: string) {
async unfreeze(content: string): Promise<void> {
debug(`Unfreezing PR: #${this.id}`);
const id = await this.publishComment(content);

this.metadata.commentID = id === undefined ? id : id.toString();
await this.metadata.setMetadata();
}

async publishComment(content: string) {
async publishComment(content: string): Promise<number | undefined> {
if (this.metadata.commentID) {
this.updateComment(content);
return;
Expand Down Expand Up @@ -100,7 +100,10 @@ export class PullRequest {
return data;
}

static async getPullRequest(id: number, octokit: CustomOctokit) {
static async getPullRequest(
id: number,
octokit: CustomOctokit
): Promise<PullRequest> {
return new PullRequest(id, octokit, await Metadata.getMetadata(id));
}
}
4 changes: 2 additions & 2 deletions src/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export class Tag {
return this._latest;
}

isFreezed(tagPolicy: string[]) {
isFreezed(tagPolicy: string[]): boolean {
if (this.latest === undefined) false;

return tagPolicy.some(regex =>
new RegExp(regex).test(this.latest as string)
);
}

static async getLatestTag() {
static async getLatestTag(): Promise<string | undefined> {
// Get latest tag sorted by date, currently impossible by using GitHub REST API
const { stdout, stderr } = await promiseExec(
// Get rid of new lines - it causes issues when regex is to explicit (including `$`)
Expand Down

0 comments on commit ba4b61e

Please sign in to comment.