@@ -11,7 +11,8 @@ import {
1111 preventPrCommitLinkLoss ,
1212 preventPrCompareLinkLoss ,
1313 prCommitUrlRegex ,
14- prCompareUrlRegex
14+ prCompareUrlRegex ,
15+ getCurrentCommittish
1516} from '../source/github-helpers' ;
1617
1718test ( 'getConversationNumber' , t => {
@@ -207,3 +208,92 @@ test('preventPrCommitLinkLoss', t => {
207208 'It should ignore Markdown links'
208209 ) ;
209210} ) ;
211+
212+ // The titles supplied here listed here are real, not guessed, except the error tester
213+ test ( 'getCurrentCommittish' , t => {
214+ // Error testing
215+ t . is ( getCurrentCommittish (
216+ '/' ,
217+ 'some page title'
218+ ) , undefined , 'It should never throw with valid input' ) ;
219+ t . throws ( ( ) => getCurrentCommittish (
220+ 'https://github.com' ,
221+ 'github.com'
222+ ) ) ;
223+
224+ // Root
225+ t . is ( getCurrentCommittish (
226+ '/typescript-eslint/typescript-eslint' ,
227+ 'typescript-eslint/typescript-eslint: Monorepo for all the tooling which enables ESLint to support TypeScript'
228+ ) , undefined ) ;
229+ t . is ( getCurrentCommittish (
230+ '/typescript-eslint/typescript-eslint/tree/chore/lerna-4' ,
231+ 'typescript-eslint/typescript-eslint at chore/lerna-4'
232+ ) , 'chore/lerna-4' ) ;
233+
234+ // Sub folder
235+ t . is ( getCurrentCommittish (
236+ '/typescript-eslint/typescript-eslint/tree/master/docs' ,
237+ 'typescript-eslint/docs at master · typescript-eslint/typescript-eslint'
238+ ) , 'master' ) ;
239+ t . is ( getCurrentCommittish (
240+ '/typescript-eslint/typescript-eslint/tree/chore/lerna-4/docs' ,
241+ 'typescript-eslint/docs at chore/lerna-4 · typescript-eslint/typescript-eslint'
242+ ) , 'chore/lerna-4' ) ;
243+
244+ // Sub sub folder
245+ t . is ( getCurrentCommittish (
246+ '/typescript-eslint/typescript-eslint/tree/master/docs/getting-started' ,
247+ 'typescript-eslint/docs/getting-started at master · typescript-eslint/typescript-eslint'
248+ ) , 'master' ) ;
249+ t . is ( getCurrentCommittish (
250+ '/typescript-eslint/typescript-eslint/tree/chore/lerna-4/docs/getting-started' ,
251+ 'typescript-eslint/docs/getting-started at chore/lerna-4 · typescript-eslint/typescript-eslint'
252+ ) , 'chore/lerna-4' ) ;
253+
254+ // File
255+ t . is ( getCurrentCommittish (
256+ '/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/README.md' ,
257+ 'typescript-eslint/README.md at master · typescript-eslint/typescript-eslint'
258+ ) , 'master' ) ;
259+ t . is ( getCurrentCommittish (
260+ '/typescript-eslint/typescript-eslint/blob/chore/lerna-4/docs/getting-started/README.md' ,
261+ 'typescript-eslint/README.md at chore/lerna-4 · typescript-eslint/typescript-eslint'
262+ ) , 'chore/lerna-4' ) ;
263+
264+ // Editing file
265+ t . is ( getCurrentCommittish (
266+ '/typescript-eslint/typescript-eslint/edit/master/docs/getting-started/README.md' ,
267+ 'Editing typescript-eslint/README.md at master · typescript-eslint/typescript-eslint'
268+ ) , 'master' ) ;
269+ t . is ( getCurrentCommittish (
270+ '/typescript-eslint/typescript-eslint/edit/chore/lerna-4/docs/getting-started/README.md' ,
271+ 'Editing typescript-eslint/README.md at chore/lerna-4 · typescript-eslint/typescript-eslint'
272+ ) , 'chore/lerna-4' ) ;
273+
274+ // Blame
275+ t . is ( getCurrentCommittish (
276+ '/typescript-eslint/typescript-eslint/blame/master/docs/getting-started/README.md' ,
277+ 'typescript-eslint/docs/getting-started/README.md at master · typescript-eslint/typescript-eslint'
278+ ) , 'master' ) ;
279+ t . is ( getCurrentCommittish (
280+ '/typescript-eslint/typescript-eslint/blame/chore/lerna-4/docs/getting-started/README.md' ,
281+ 'typescript-eslint/docs/getting-started/README.md at chore/lerna-4 · typescript-eslint/typescript-eslint'
282+ ) , 'chore/lerna-4' ) ;
283+
284+ // Commits
285+ t . is ( getCurrentCommittish (
286+ '/typescript-eslint/typescript-eslint/commits/master/docs/getting-started/README.md' ,
287+ 'History for docs/getting-started/README.md - typescript-eslint/typescript-eslint'
288+ ) , 'master' ) ;
289+ t . is ( getCurrentCommittish (
290+ '/typescript-eslint/typescript-eslint/commits/chore/lerna-4/docs/getting-started/README.md' ,
291+ 'History for docs/getting-started/README.md - typescript-eslint/typescript-eslint'
292+ ) , 'chore' ) ; // Wrong, but
293+
294+ // Single commit
295+ t . is ( getCurrentCommittish (
296+ '/typescript-eslint/typescript-eslint/commit/795fd1c529ee58e97283c9ddf8463703517b50ab' ,
297+ 'chore: add markdownlint (#1889) · typescript-eslint/typescript-eslint@795fd1c'
298+ ) , '795fd1c529ee58e97283c9ddf8463703517b50ab' ) ;
299+ } ) ;
0 commit comments