Skip to content

Commit 9c69025

Browse files
author
William Wilkinson
committed
Fix bug with regex not matching without a trailing space.
Fixes #5
1 parent 70d4b06 commit 9c69025

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Verify Linked Issue Action
2-
A GitHub action that verifies your pull request contains a reference to an issue.
2+
A GitHub action that verifies your pull request contains a reference to an issue.
33

44
On a PR that does not include a linked issue or reference to an issue in the body, the check should fail and a comment will be added to the PR.
55

@@ -46,7 +46,7 @@ If you want a more complex message, consider using a static template file. (Supp
4646
There are two options when using template files:
4747
4848
* Option 1) Default File Path: Add a file to .github called VERIFY_PR_COMMENT_TEMPLATE.md. The content of this file will be used as the fail comment in the PR.
49-
* Option 2) Speciy a filename input with the path to a template file.
49+
* Option 2) Speciy a filename input with the path to a template file.
5050
```yaml
5151
- name: Verify Linked Issue
5252
uses: hattan/[email protected]
@@ -64,10 +64,6 @@ There are two options when using template files:
6464
6565
![Failed Build log](images/failed1.png "Failed Build log")
6666
## Known Issues
67-
* There must be a space after the issue number (ie "#12 " not "#12".) This is due to the way the RegEx is structured and will be resolved in a future release.
68-
6967
* The Issue reference by # needs to be in the body, we don't currently look in the title. That is a future enhancement.
7068
7169
v1
72-
73-

src/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
const core = require('@actions/core')
33
const github = require('@actions/github');
44
const context = github.context;
@@ -28,29 +28,29 @@ async function checkBodyForValidIssue(context, github){
2828
return false;
2929
}
3030
core.debug(`Checking PR Body: "${body}"`)
31-
const re = /#(.*?)[\s]/g;
31+
const re = /(\s)#\d+(?!\S)/g;
3232
const matches = body.match(re);
3333
core.debug(`regex matches: ${matches}`)
3434
if(matches){
35-
for(let i=0,len=matches.length;i<len;i++){
36-
let match = matches[i];
35+
matches.filter(match => match !== '').map(match => {
3736
let issueId = match.replace('#','').trim();
3837
core.debug(`verifying match is a valid issue issueId: ${issueId}`)
3938
try{
40-
let issue = await octokit.rest.issues.get({
39+
octokit.rest.issues.get({
4140
owner: context.repo.owner,
4241
repo: context.repo.repo,
4342
issue_number: issueId,
43+
}).then(issue => {
44+
if(issue){
45+
core.debug(`Found issue in PR Body ${issueId}`);
46+
return true;
47+
}
4448
});
45-
if(issue){
46-
core.debug(`Found issue in PR Body ${issueId}`);
47-
return true;
48-
}
4949
}
5050
catch{
5151
core.debug(`#${issueId} is not a valid issue.`);
5252
}
53-
}
53+
})
5454
}
5555
return false;
5656
}
@@ -60,7 +60,7 @@ async function checkEventsListForConnectedEvent(context, github){
6060
let pull = await octokit.rest.issues.listEvents({
6161
owner: context.repo.owner,
6262
repo: context.repo.repo,
63-
issue_number: context.payload.pull_request.number
63+
issue_number: context.payload.pull_request.number
6464
});
6565

6666
if(pull.data){
@@ -116,7 +116,7 @@ async function run() {
116116

117117
core.debug('Starting Linked Issue Verification!');
118118
await verifyLinkedIssue();
119-
119+
120120
} catch (err) {
121121
core.error(`Error verifying linked issue.`)
122122
core.error(err)

0 commit comments

Comments
 (0)