|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import { default as assert } from 'assert'; |
7 | | -import { parseIssueExpressionOutput, ISSUE_OR_URL_EXPRESSION } from '../../github/utils'; |
| 7 | +import * as vscode from 'vscode'; |
| 8 | +import { getIssueOrURLExpression, ISSUE_OR_URL_EXPRESSION, parseIssueExpressionOutput } from '../../github/utils'; |
8 | 9 |
|
9 | 10 | describe('Issues utilities', function () { |
10 | 11 | it('regular expressions', async function () { |
@@ -65,4 +66,44 @@ describe('Issues utilities', function () { |
65 | 66 | assert.strictEqual(prUrlHttpParsed?.name, 'repo'); |
66 | 67 | assert.strictEqual(prUrlHttpParsed?.owner, 'owner'); |
67 | 68 | }); |
| 69 | + |
| 70 | + it('getIssueOrURLExpression matches enterprise host URLs', function () { |
| 71 | + const enterpriseExpression = getIssueOrURLExpression(vscode.Uri.parse('https://my.ghe.host')); |
| 72 | + |
| 73 | + // Enterprise host URL is matched |
| 74 | + const enterpriseIssueUrl = 'https://my.ghe.host/org/repo/issues/123'; |
| 75 | + const enterpriseIssueParsed = parseIssueExpressionOutput(enterpriseIssueUrl.match(enterpriseExpression)); |
| 76 | + assert.strictEqual(enterpriseIssueParsed?.issueNumber, 123); |
| 77 | + assert.strictEqual(enterpriseIssueParsed?.commentNumber, undefined); |
| 78 | + assert.strictEqual(enterpriseIssueParsed?.name, 'repo'); |
| 79 | + assert.strictEqual(enterpriseIssueParsed?.owner, 'org'); |
| 80 | + |
| 81 | + // Enterprise PR URL is matched |
| 82 | + const enterprisePrUrl = 'https://my.ghe.host/org/repo/pull/456'; |
| 83 | + const enterprisePrParsed = parseIssueExpressionOutput(enterprisePrUrl.match(enterpriseExpression)); |
| 84 | + assert.strictEqual(enterprisePrParsed?.issueNumber, 456); |
| 85 | + assert.strictEqual(enterprisePrParsed?.name, 'repo'); |
| 86 | + assert.strictEqual(enterprisePrParsed?.owner, 'org'); |
| 87 | + |
| 88 | + // Enterprise comment URL is matched |
| 89 | + const enterpriseCommentUrl = 'https://my.ghe.host/org/repo/issues/789#issuecomment-12345'; |
| 90 | + const enterpriseCommentParsed = parseIssueExpressionOutput(enterpriseCommentUrl.match(enterpriseExpression)); |
| 91 | + assert.strictEqual(enterpriseCommentParsed?.issueNumber, 789); |
| 92 | + assert.strictEqual(enterpriseCommentParsed?.commentNumber, 12345); |
| 93 | + assert.strictEqual(enterpriseCommentParsed?.name, 'repo'); |
| 94 | + assert.strictEqual(enterpriseCommentParsed?.owner, 'org'); |
| 95 | + |
| 96 | + // github.com URLs are still matched when an enterprise URI is provided |
| 97 | + const dotComUrl = 'https://github.com/microsoft/vscode/issues/96'; |
| 98 | + const dotComParsed = parseIssueExpressionOutput(dotComUrl.match(enterpriseExpression)); |
| 99 | + assert.strictEqual(dotComParsed?.issueNumber, 96); |
| 100 | + assert.strictEqual(dotComParsed?.name, 'vscode'); |
| 101 | + assert.strictEqual(dotComParsed?.owner, 'microsoft'); |
| 102 | + |
| 103 | + // Without an enterprise URI, only github.com URLs are matched as full URLs |
| 104 | + const defaultExpression = getIssueOrURLExpression(); |
| 105 | + const enterpriseAgainstDefault = parseIssueExpressionOutput(enterpriseIssueUrl.match(defaultExpression)); |
| 106 | + // The owner/repo/number should not match the URL form (the alternate `owner/repo#num` form is also not present here). |
| 107 | + assert.strictEqual(enterpriseAgainstDefault, undefined); |
| 108 | + }); |
68 | 109 | }); |
0 commit comments