-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,54 @@ | ||
import { Action } from './action'; | ||
import * as core from '@actions/core'; | ||
import * as github from '@actions/github'; | ||
import { geocode } from './geocode'; | ||
import { | ||
formatResults, | ||
generateTokens, | ||
getOctokit, | ||
requiresAction, | ||
} from './util'; | ||
|
||
Action.run(); | ||
export async function run() { | ||
core.notice('Starting action'); | ||
try { | ||
const { context } = github; | ||
const payload = context.payload; | ||
const commentBody = context.payload.comment!.body as string; | ||
|
||
core.debug(JSON.stringify(payload)); | ||
|
||
if (payload?.comment?.id == null) { | ||
core.setFailed('no comment found in payload'); | ||
|
||
return; | ||
} | ||
|
||
if (!requiresAction(payload, commentBody)) { | ||
core.warning('no action required'); | ||
|
||
return; | ||
} | ||
|
||
core.notice('getting octokit'); | ||
const octokit = getOctokit(); | ||
|
||
core.notice('finding addresses'); | ||
const { addresses } = generateTokens(commentBody); | ||
core.notice(`addresses: ${addresses}`); | ||
|
||
const results = await geocode(addresses, core.getInput('API_KEY')); | ||
|
||
core.notice('updating comments'); | ||
await octokit.rest.issues.updateComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: payload.comment.id, | ||
body: formatResults(results), | ||
}); | ||
} catch (e) { | ||
core.error(e); | ||
core.setFailed(e.message); | ||
} | ||
} | ||
|
||
run() |