-
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
4 changed files
with
66 additions
and
53 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { patchIssue } from './block-formatter'; | ||
|
||
if(process.argv.length != 6) { | ||
console.log(process.argv) | ||
console.log(`Usage:\ncli TOKEN OWNER REPO ISSUE`) | ||
} else { | ||
|
||
const [, , authToken, owner, repo, number] = process.argv; | ||
|
||
patchIssue(authToken, owner, repo, parseInt(number)).catch(error => { | ||
console.error('Failed:', error.message) | ||
process.exit(1) | ||
}) | ||
} |
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,60 +1,13 @@ | ||
import * as core from '@actions/core'; | ||
import * as github from '@actions/github'; | ||
import { patchCodeBlocks } from './block-formatter'; | ||
import { patchIssue } from './block-formatter'; | ||
|
||
(async () => { | ||
|
||
const authToken = core.getInput('repo-token'); | ||
|
||
const octokit = github.getOctokit(authToken); | ||
|
||
const {owner, repo, number} = github.context.issue; | ||
|
||
console.log(`Repo: ${owner}/${repo}`) | ||
console.log(`Issue: ${number}`) | ||
|
||
console.log('Retrieving issue details...') | ||
|
||
const response = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}", { | ||
owner, | ||
repo, | ||
issue_number: number, | ||
}); | ||
|
||
if(response.status != 200) { | ||
core.setFailed(`Failed to fetch issue data. Server responded with ${response.status}`) | ||
} | ||
|
||
const issue = response.data; | ||
|
||
console.log(`Issue title: ${issue.title}`) | ||
console.log(`Issue body:\n${issue.body}\n`) | ||
console.log(`Patching issue body...`) | ||
|
||
const [patchedBody, patchCount] = patchCodeBlocks(issue.body); | ||
|
||
if(patchCount < 1) { | ||
console.log('No lines where patched. Skipping update.') | ||
// No need to update the issue body, since we found no logfmt lines | ||
return | ||
} | ||
|
||
console.log(`Patch count: ${patchCount}`) | ||
console.log(`Saving issue body...`) | ||
|
||
const saveResponse = await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { | ||
owner, | ||
repo, | ||
issue_number: number, | ||
body: patchedBody, | ||
}) | ||
|
||
console.log('Response:') | ||
console.log(saveResponse.data) | ||
|
||
if(saveResponse.status != 200) { | ||
core.setFailed(`Failed to save issue data. Server responded with ${response.status}`) | ||
} | ||
|
||
})().catch(error => core.setFailed(error.message)) | ||
await patchIssue(authToken, owner, repo, number) | ||
|
||
})().catch(error => core.setFailed(error.message)) |
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