Skip to content
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ octodemo/template-demo-github-user-search
| --------------------------| -------- | ------------------------------- |
| `github_token` | `true` | PAT(Personal Access Token) for accessing the issues on the repository, defaults to `${{ github.token }}`. |
| `issue_id` | `true` | The id of the issue to load the content from.|
| `repository` | `false` | The repository where the issue lives. Defaults to the current repository.|
| `separator` | `false` | The separator between the fields defaults to `###` which is markdown h3 which GitHub is currently defaulting to |
| `label_marker_start` | `true` | The characters to match for the beginning of a label |
| `label_marker_end` | `true` | The characters to match for the ending of a label |
Expand All @@ -48,6 +49,7 @@ steps:
uses: peter-murray/issue-forms-body-parser@v1.1.0
with:
issue_id: ${{ github.event.issue.number }}
repository: octokit/rest.js
separator: '###'
label_marker_start: '>>'
label_marker_end: '<<'
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ inputs:
default: ${{ github.token }}
required: true

repository:
description: The GitHub repository where the issue lives
default: ${{ github.repository }}
required: true

issue_id:
description: The id of the issue to use to extract a payload from the body
required: true
Expand Down
10 changes: 7 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ async function run() {
, parserSeparator = getRequiredInputValue('separator')
, parserMarkerStart = getRequiredInputValue('label_marker_start')
, parserMarkerEnd = getRequiredInputValue('label_marker_end')
, repository = getRequiredInputValue('repository')
;

const issueUtil = new IssueUtil(githubToken)
, parser = new Parser(parserSeparator, parserMarkerStart, parserMarkerEnd)
;

const issueBody = await issueUtil.getIssueBody(issueId);
const issueBody = await issueUtil.getIssueBody(issueId, repository);

const parsed = parser.parse(issueBody);
if (parsed !== undefined) {
Expand Down Expand Up @@ -5885,9 +5886,11 @@ module.exports = class IssueUtil {
this.octokit = github.getOctokit(token);
}

getIssueBody(id) {
getIssueBody(id, repository) {
const [owner, repo] = repository.split('/');

return this.octokit.issues.get({
...github.context.repo,
...{owner, repo},
issue_number: id
}).then(result => {
if (result.status !== 200) {
Expand All @@ -5900,6 +5903,7 @@ module.exports = class IssueUtil {
}
}


/***/ }),

/***/ 657:
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ async function run() {
, parserSeparator = getRequiredInputValue('separator')
, parserMarkerStart = getRequiredInputValue('label_marker_start')
, parserMarkerEnd = getRequiredInputValue('label_marker_end')
, repository = getRequiredInputValue('repository')
;

const issueUtil = new IssueUtil(githubToken)
, parser = new Parser(parserSeparator, parserMarkerStart, parserMarkerEnd)
;

const issueBody = await issueUtil.getIssueBody(issueId);
const issueBody = await issueUtil.getIssueBody(issueId, repository);

const parsed = parser.parse(issueBody);
if (parsed !== undefined) {
Expand Down
8 changes: 5 additions & 3 deletions src/IssueUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ module.exports = class IssueUtil {
this.octokit = github.getOctokit(token);
}

getIssueBody(id) {
getIssueBody(id, repository) {
const [owner, repo] = repository.split('/');
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only issue here is that it is possible for a user to provide an input that is not in this form and we would not detect this of fail nicely with the following call.

I would suggest that we validate the repository input early in the execution when we obtain that value from the user inputs and pass a consistent {owner: '', repo: ''} object to this function.


return this.octokit.issues.get({
...github.context.repo,
...{owner, repo},
issue_number: id
}).then(result => {
if (result.status !== 200) {
Expand All @@ -22,4 +24,4 @@ module.exports = class IssueUtil {
throw err;
});
}
}
}