Skip to content

Commit b403a46

Browse files
committed
Add OctokitResponse type
1 parent 17257b2 commit b403a46

2 files changed

Lines changed: 29 additions & 32 deletions

File tree

.github/actions/file/src/index.ts

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Finding, ResolvedFiling, RepeatedFiling, FindingGroupIssue, Filing} from './types.d.js'
1+
import type {Finding, ResolvedFiling, RepeatedFiling, FindingGroupIssue, Filing, IssueResponse} from './types.d.js'
22
import process from 'node:process'
33
import core from '@actions/core'
44
import {Octokit} from '@octokit/core'
@@ -11,7 +11,7 @@ import {isResolvedFiling} from './isResolvedFiling.js'
1111
import {openIssue} from './openIssue.js'
1212
import {reopenIssue} from './reopenIssue.js'
1313
import {updateFilingsWithNewFindings} from './updateFilingsWithNewFindings.js'
14-
import { OctokitResponse } from '@octokit/types'
14+
import {OctokitResponse} from '@octokit/types'
1515
const OctokitWithThrottling = Octokit.plugin(throttling)
1616

1717
export default async function () {
@@ -23,7 +23,7 @@ export default async function () {
2323
const cachedFilings: (ResolvedFiling | RepeatedFiling)[] = JSON.parse(
2424
core.getInput('cached_filings', {required: false}) || '[]',
2525
)
26-
const shouldOpenGroupedIssues = core.getBooleanInput("open_grouped_issues")
26+
const shouldOpenGroupedIssues = core.getBooleanInput('open_grouped_issues')
2727
core.debug(`Input: 'findings: ${JSON.stringify(findings)}'`)
2828
core.debug(`Input: 'repository: ${repoWithOwner}'`)
2929
core.debug(`Input: 'screenshot_repository: ${screenshotRepo}'`)
@@ -56,7 +56,7 @@ export default async function () {
5656
const trackingIssueUrls: Record<string, string> = {}
5757

5858
for (const filing of filings) {
59-
let response: OctokitResponse<any> | undefined;
59+
let response: OctokitResponse<IssueResponse> | undefined
6060
try {
6161
if (isResolvedFiling(filing)) {
6262
// Close the filing’s issue (if necessary)
@@ -108,39 +108,28 @@ export default async function () {
108108
// Open tracking issues for groups with >1 new issue and link back from each
109109
// new issue
110110
if (shouldOpenGroupedIssues) {
111-
for (const [problemShort, issues] of Object.entries(
112-
newIssuesByProblemShort,
113-
)) {
111+
for (const [problemShort, issues] of Object.entries(newIssuesByProblemShort)) {
114112
if (issues.length > 1) {
115-
const title: string = `${problemShort} issues`;
116-
const body: string =
117-
`# ${problemShort} issues\n\n` +
118-
issues.map((issue) => `- [ ] ${issue.url}`).join("\n");
113+
const title: string = `${problemShort} issues`
114+
const body: string = `# ${problemShort} issues\n\n` + issues.map(issue => `- [ ] ${issue.url}`).join('\n')
119115
try {
120-
const trackingResponse = await octokit.request(
121-
`POST /repos/${repoWithOwner}/issues`,
122-
{
123-
owner: repoWithOwner.split("/")[0],
124-
repo: repoWithOwner.split("/")[1],
125-
title,
126-
body,
127-
},
128-
);
129-
const trackingUrl: string = trackingResponse.data.html_url;
130-
trackingIssueUrls[problemShort] = trackingUrl;
131-
core.info(
132-
`Opened tracking issue for '${problemShort}' with ${issues.length} issues.`,
133-
);
116+
const trackingResponse = await octokit.request(`POST /repos/${repoWithOwner}/issues`, {
117+
owner: repoWithOwner.split('/')[0],
118+
repo: repoWithOwner.split('/')[1],
119+
title,
120+
body,
121+
})
122+
const trackingUrl: string = trackingResponse.data.html_url
123+
trackingIssueUrls[problemShort] = trackingUrl
124+
core.info(`Opened tracking issue for '${problemShort}' with ${issues.length} issues.`)
134125
} catch (error) {
135-
core.warning(
136-
`Failed to open tracking issue for '${problemShort}': ${error}`,
137-
);
126+
core.warning(`Failed to open tracking issue for '${problemShort}': ${error}`)
138127
}
139128
}
140129
}
141130
}
142131

143-
core.setOutput("filings", JSON.stringify(filings));
144-
core.debug(`Output: 'filings: ${JSON.stringify(filings)}'`);
145-
core.info("Finished 'file' action");
132+
core.setOutput('filings', JSON.stringify(filings))
133+
core.debug(`Output: 'filings: ${JSON.stringify(filings)}'`)
134+
core.info("Finished 'file' action")
146135
}

.github/actions/file/src/types.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export type Issue = {
1818
state?: 'open' | 'reopened' | 'closed'
1919
}
2020

21+
export type IssueResponse = {
22+
id: number
23+
node_id: string
24+
number: number
25+
html_url: string
26+
title: string
27+
}
28+
2129
export type ResolvedFiling = {
2230
findings: never[]
2331
issue: Issue
@@ -38,4 +46,4 @@ export type Filing = ResolvedFiling | NewFiling | RepeatedFiling
3846
export type FindingGroupIssue = {
3947
url: string
4048
id: number
41-
};
49+
}

0 commit comments

Comments
 (0)