|
1 | 1 | import * as core from '@actions/core'
|
2 |
| -import { wait } from './wait' |
| 2 | +import * as github from '@actions/github' |
| 3 | + |
3 | 4 |
|
4 |
| -/** |
5 |
| - * The main function for the action. |
6 |
| - * @returns {Promise<void>} Resolves when the action is complete. |
7 |
| - */ |
8 | 5 | export async function run(): Promise<void> {
|
9 | 6 | try {
|
10 |
| - const ms: string = core.getInput('milliseconds') |
| 7 | + const mainBranch: string = core.getInput('mainBranch') ?? 'dev' |
| 8 | + const token: string = core.getInput('token') |
| 9 | + |
| 10 | + const octokit = github.getOctokit(token) |
| 11 | + const latestRelease = await octokit.rest.repos.getLatestRelease({ ...github.context.repo, }) |
11 | 12 |
|
12 |
| - // Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true |
13 |
| - core.debug(`Waiting ${ms} milliseconds ...`) |
| 13 | + const pullRequests = await octokit.rest.pulls.list({ |
| 14 | + ...github.context.repo, |
| 15 | + base: latestRelease.data.target_commitish, |
| 16 | + head: mainBranch, |
| 17 | + state: 'closed', |
| 18 | + }); |
| 19 | + const linearTickets = await Promise.all(pullRequests.data.map(async pr => { |
| 20 | + const comments = await octokit.rest.issues.listComments({ |
| 21 | + ...github.context.repo, |
| 22 | + issue_number: pr.number, |
| 23 | + }); |
| 24 | + const linearComment = comments.data.find(c => { |
| 25 | + core.debug(`Comment by ${c.performed_via_github_app}`) |
| 26 | + return c.performed_via_github_app?.name === 'linear' |
| 27 | + }) |
| 28 | + const ticket = linearComment?.body?.match(/\bRAY-\d+\b/) |
| 29 | + return ticket?.[0].match |
| 30 | + }).filter(Boolean)) |
14 | 31 |
|
15 |
| - // Log the current timestamp, wait, then log the new timestamp |
16 |
| - core.debug(new Date().toTimeString()) |
17 |
| - await wait(parseInt(ms, 10)) |
18 |
| - core.debug(new Date().toTimeString()) |
| 32 | + core.debug(`Tickets found ${linearTickets.join()}`) |
19 | 33 |
|
20 |
| - // Set outputs for other workflow steps to use |
21 |
| - core.setOutput('time', new Date().toTimeString()) |
22 | 34 | } catch (error) {
|
23 | 35 | // Fail the workflow run if an error occurs
|
24 | 36 | if (error instanceof Error) core.setFailed(error.message)
|
|
0 commit comments