Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
refactor: enhance github url regex (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersDJohnson authored Oct 26, 2020
1 parent 87ce12b commit 4713d9e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ resolved super/duper/#11
https://github.com/example_user/example_project/issues/3
https://github.com/example_user/example_project/issues/4
https://github.com/example_user/example_project/issues/5#some-hash
https://git.myenterprise.com/example_user/example_project/issues/5
https://git.subdomain.myenterprise.com/example_user/example_project/issues/5
https://www.github.com/example_user/example_project/issues/6
https://github.com/example_user/example_project/issues/7
https://github.com/example_user/example_project/issues/8
Expand All @@ -38,12 +40,24 @@ describe('github finder', () => {
issueNumber: '4',
name: '4',
},
{
fullLinkedUrl: 'https://github.com/example_user/example_project/issues/5',
project: 'example_user/example_project',
issueNumber: '5',
name: '5',
},
{
fullLinkedUrl: 'https://git.myenterprise.com/example_user/example_project/issues/5',
project: 'example_user/example_project',
issueNumber: '5',
name: '5',
},
{
fullLinkedUrl: 'https://git.subdomain.myenterprise.com/example_user/example_project/issues/5',
project: 'example_user/example_project',
issueNumber: '5',
name: '5',
},
{
fullLinkedUrl: 'https://www.github.com/example_user/example_project/issues/6',
project: 'example_user/example_project',
Expand Down Expand Up @@ -128,12 +142,39 @@ describe('github finder', () => {
expect(githubFinder({ body })).toEqual(expectation);
});

it('should find ticket with period at end of URL', () => {
const PRBody = `
## Summary
https://git.you.com/wow/woohoo/issues/27158.
### Addresses issue
prod issue
### Steps to reproduce & screenshots/GIFs
`;
const expectation = {
tickets: [
{
fullLinkedUrl: 'https://git.you.com/wow/woohoo/issues/27158',
project: 'wow/woohoo',
issueNumber: '27158',
name: '27158',
},
],
name: 'github',
};

expect(githubFinder({ body: PRBody })).toEqual(expectation);
});

it('should return 2 tickets, not one, if they grouped together by only words or whitespace', () => {
const PRBody = `
## Summary
https://git.you.com/wow/woohoo/issues/27158 and https://git.you.com/wow/woohoo/issue/27166
https://git.you.com/wow/woohoo/issues/27158 and https://git.you.com/wow/woohoo/issues/27166
### Addresses issue
Expand All @@ -149,7 +190,7 @@ describe('github finder', () => {
name: '27158',
},
{
fullLinkedUrl: 'https://git.you.com/wow/woohoo/issue/27166',
fullLinkedUrl: 'https://git.you.com/wow/woohoo/issues/27166',
project: 'wow/woohoo',
issueNumber: '27166',
name: '27166',
Expand Down Expand Up @@ -179,6 +220,26 @@ describe('github finder', () => {
expect(githubFinder({ body: PRBody })).toEqual(expectation);
});

it('should not think other GitHub URL is a ticket', () => {
const PRBody = `
## Summary
https://git.you.com/wow/woohoo/tree/main/config/123
### Addresses issue
prod issue
### Steps to reproduce & screenshots/GIFs
`;
const expectation = {
tickets: [],
name: 'github',
};

expect(githubFinder({ body: PRBody })).toEqual(expectation);
});

it('should return no tickets if there are no ticket types', () => {
const expectation = {
tickets: [],
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ticketFinder/finders/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const githubDomain = config.get('github:domain') || 'https://github.com';
const owner = config.get('github:owner');
const repo = config.get('github:repo');

const GITHUB_QUALIFIED_URL = /(https:\/\/(?:www.git|git)(?:\.\w+|\w+)\.com\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+\/[^pull]+\w+\/\d+)/;
const GITHUB_QUALIFIED_URL = /(https:\/\/(?:www.git|git)[^\s]*(\.[^\s]+)+\/[^\s]+\/[^\s]+\/issues\/\d+)/;
const GITHUB_QUALIFIED_NUMBER_URL = /https:\/\/(?:www.git|git).*\..+\/(\d+)/;
const CLOSE_ISSUE_SYNTAX = /(?:close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s(\S.*\/\S.*#\d+|#\d+)/;
const CLOSE_SYNTAX_NUMBER = /#(\d+)/;
Expand Down

0 comments on commit 4713d9e

Please sign in to comment.