Skip to content

Commit

Permalink
fix: type error
Browse files Browse the repository at this point in the history
  • Loading branch information
knokmki612 committed Sep 12, 2021
1 parent 0375e90 commit 3d93829
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
42 changes: 36 additions & 6 deletions src/doorkeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,44 @@ const options = {
method: "get",
headers: { Authorization: `Bearer ${process.env.DOORKEEPER_TOKEN}` },
} as const;
const request = async (api: string) =>
(await fetch(`${baseUrl}${api}`, options)).json();
const request = async <T>(api: string) =>
(await fetch(`${baseUrl}${api}`, options)).json() as Promise<T>;

type DoorkeeperEvent = {
title: string;
id: number;
starts_at: string;
ends_at: string;
venue_name: string;
address: string;
lat: string;
long: string;
ticket_limit: number;
published_at: string;
group: number;
description: string;
public_url: string;
participants: number;
waitlisted: number;
};

type DoorkeeperGroup = {
id: number;
name: string;
country_code: string;
logo: string;
description: string;
public_url: string;
members_count: number;
};

export const getEvents = (group = "") => {
if (group === "") return request("/events");
return request(`/groups/${group}/events`);
if (group === "") return request<{ event: DoorkeeperEvent }[]>("/events");
return request<{ event: DoorkeeperEvent }[]>(`/groups/${group}/events`);
};

export const getEvent = (id: string) => request(`/events/${id}`);
export const getEvent = (id: string) =>
request<{ event: DoorkeeperEvent }>(`/events/${id}`);

export const getGroup = (group: string) => request(`/groups/${group}`);
export const getGroup = (group: string) =>
request<{ group: DoorkeeperGroup }>(`/groups/${group}`);
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const main = async () => {
const { owner, repo } = context.repo;
const octokit = getOctokit(getInput("GITHUB_TOKEN", { required: true }));
const q = `repo:${owner}/${repo} state:open`;
const issues = await octokit.search.issuesAndPullRequests({ q });
const issues = await octokit.rest.search.issuesAndPullRequests({ q });
const events = await getEvents(getInput("DOORKEEPER_GROUP"));

await Promise.all(
Expand All @@ -30,12 +30,12 @@ const main = async () => {
events,
});

await octokit.issues.update({
await octokit.rest.issues.update({
...issue,
state: "closed",
title: normalize(title),
});
await octokit.issues.createComment({ ...issue, body: message });
await octokit.rest.issues.createComment({ ...issue, body: message });
})
);
};
Expand Down

0 comments on commit 3d93829

Please sign in to comment.