11import settings from '../settings' ;
22import { GithubSettings } from './settings' ;
33import * as utils from './utils' ;
4- import { Octokit as GitHubApi , RestEndpointMethodTypes } from '@octokit/rest' ;
5- import { IssuesListForRepoResponseData , PullsListResponseData } from " @octokit/types" ;
4+ import { Octokit as GitHubApi , RestEndpointMethodTypes } from '@octokit/rest' ;
5+ import { Endpoints } from ' @octokit/types' ;
66import GitlabHelper from './gitlabHelper' ;
77
8+ type IssuesListForRepoResponseData =
9+ Endpoints [ 'GET /repos/{owner}/{repo}/issues' ] [ 'response' ] [ 'data' ] ;
10+ type PullsListResponseData =
11+ Endpoints [ 'GET /repos/{owner}/{repo}/pulls' ] [ 'response' ] [ 'data' ] ;
12+
813const gitHubLocation = 'https://github.com' ;
914
1015export default class GithubHelper {
@@ -20,10 +25,12 @@ export default class GithubHelper {
2025 delayInMs : number ;
2126 useIssuesForAllMergeRequests : boolean ;
2227
23- constructor ( githubApi : GitHubApi ,
24- githubSettings : GithubSettings ,
25- gitlabHelper : GitlabHelper ,
26- useIssuesForAllMergeRequests : boolean ) {
28+ constructor (
29+ githubApi : GitHubApi ,
30+ githubSettings : GithubSettings ,
31+ gitlabHelper : GitlabHelper ,
32+ useIssuesForAllMergeRequests : boolean
33+ ) {
2734 this . githubApi = githubApi ;
2835 this . githubUrl = githubSettings . baseUrl
2936 ? githubSettings . baseUrl
@@ -54,7 +61,7 @@ export default class GithubHelper {
5461 // get an array of GitHub milestones for the new repo
5562 let result = await this . githubApi . repos . get ( {
5663 owner : this . githubOwner ,
57- repo : this . githubRepo
64+ repo : this . githubRepo ,
5865 } ) ;
5966
6067 this . repoId = result . data . id ;
@@ -209,9 +216,12 @@ export default class GithubHelper {
209216 * TODO description
210217 */
211218 async createIssue ( milestones , issue ) {
212- let bodyConverted = await this . convertIssuesAndComments ( issue . description , issue ) ;
219+ let bodyConverted = await this . convertIssuesAndComments (
220+ issue . description ,
221+ issue
222+ ) ;
213223
214- let props : RestEndpointMethodTypes [ " issues" ] [ " create" ] [ " parameters" ] = {
224+ let props : RestEndpointMethodTypes [ ' issues' ] [ ' create' ] [ ' parameters' ] = {
215225 owner : this . githubOwner ,
216226 repo : this . githubRepo ,
217227 title : issue . title . trim ( ) ,
@@ -316,8 +326,9 @@ export default class GithubHelper {
316326 }
317327
318328 console . log (
319- `\t...Done creating issue comments (migrated ${ nrOfMigratedNotes } comments, skipped ${ notes . length -
320- nrOfMigratedNotes } comments)`
329+ `\t...Done creating issue comments (migrated ${ nrOfMigratedNotes } comments, skipped ${
330+ notes . length - nrOfMigratedNotes
331+ } comments)`
321332 ) ;
322333 }
323334
@@ -395,7 +406,7 @@ export default class GithubHelper {
395406 // default state is open so we don't have to update if the issue is closed.
396407 if ( issue . state !== 'closed' || githubIssue . state === 'closed' ) return ;
397408
398- let props : RestEndpointMethodTypes [ " issues" ] [ " update" ] [ " parameters" ] = {
409+ let props : RestEndpointMethodTypes [ ' issues' ] [ ' update' ] [ ' parameters' ] = {
399410 owner : this . githubOwner ,
400411 repo : this . githubRepo ,
401412 issue_number : githubIssue . number ,
@@ -418,13 +429,14 @@ export default class GithubHelper {
418429 */
419430 async createMilestone ( milestone ) {
420431 // convert from GitLab to GitHub
421- let githubMilestone : RestEndpointMethodTypes [ "issues" ] [ "createMilestone" ] [ "parameters" ] = {
422- owner : this . githubOwner ,
423- repo : this . githubRepo ,
424- title : milestone . title ,
425- description : milestone . description ,
426- state : milestone . state === 'active' ? 'open' : 'closed' ,
427- } ;
432+ let githubMilestone : RestEndpointMethodTypes [ 'issues' ] [ 'createMilestone' ] [ 'parameters' ] =
433+ {
434+ owner : this . githubOwner ,
435+ repo : this . githubRepo ,
436+ title : milestone . title ,
437+ description : milestone . description ,
438+ state : milestone . state === 'active' ? 'open' : 'closed' ,
439+ } ;
428440
429441 if ( milestone . due_date ) {
430442 githubMilestone . due_on = milestone . due_date + 'T00:00:00Z' ;
@@ -574,13 +586,13 @@ export default class GithubHelper {
574586 await this . githubApi . pulls . create ( props ) ;
575587 return Promise . resolve ( { data : null } ) ; // need to return null promise for parent to wait on
576588 } catch ( err ) {
577- if ( err . status === 422 ) {
589+ if ( err . status === 422 ) {
578590 console . error (
579591 `Pull request #${ pullRequest . iid } - attempt to create has failed, assume '${ pullRequest . source_branch } ' has already been merged => cannot migrate pull request, creating an issue instead.`
580592 ) ;
581593 // fall through to next section
582594 } else {
583- throw ( err ) ;
595+ throw err ;
584596 }
585597 }
586598 }
@@ -651,8 +663,9 @@ export default class GithubHelper {
651663 }
652664
653665 console . log (
654- `\t...Done creating pull request comments (migrated ${ nrOfMigratedNotes } pull request comments, skipped ${ notes . length -
655- nrOfMigratedNotes } pull request comments)`
666+ `\t...Done creating pull request comments (migrated ${ nrOfMigratedNotes } pull request comments, skipped ${
667+ notes . length - nrOfMigratedNotes
668+ } pull request comments)`
656669 ) ;
657670 }
658671
@@ -667,7 +680,7 @@ export default class GithubHelper {
667680 * @returns {Promise<Github.Response<Github.IssuesUpdateResponse>> }
668681 */
669682 async updatePullRequestData ( githubPullRequest , pullRequest , milestones ) {
670- let props : RestEndpointMethodTypes [ " issues" ] [ " update" ] [ " parameters" ] = {
683+ let props : RestEndpointMethodTypes [ ' issues' ] [ ' update' ] [ ' parameters' ] = {
671684 owner : this . githubOwner ,
672685 repo : this . githubRepo ,
673686 issue_number : githubPullRequest . number || githubPullRequest . iid ,
@@ -746,7 +759,7 @@ export default class GithubHelper {
746759 if ( pullRequest . state !== 'closed' || githubPullRequest . state === 'closed' )
747760 return ;
748761
749- let props : RestEndpointMethodTypes [ " issues" ] [ " update" ] [ " parameters" ] = {
762+ let props : RestEndpointMethodTypes [ ' issues' ] [ ' update' ] [ ' parameters' ] = {
750763 owner : this . githubOwner ,
751764 repo : this . githubRepo ,
752765 issue_number : githubPullRequest . number ,
@@ -825,7 +838,12 @@ export default class GithubHelper {
825838 }
826839 ) ;
827840
828- strWithMigLine = await utils . migrateAttachments ( strWithMigLine , this . repoId , settings . s3 , this . gitlabHelper ) ;
841+ strWithMigLine = await utils . migrateAttachments (
842+ strWithMigLine ,
843+ this . repoId ,
844+ settings . s3 ,
845+ this . gitlabHelper
846+ ) ;
829847
830848 return strWithMigLine ;
831849 }
@@ -899,10 +917,7 @@ export default class GithubHelper {
899917 line = position . old_line ;
900918 }
901919 const crypto = require ( 'crypto' ) ;
902- const hash = crypto
903- . createHash ( 'md5' )
904- . update ( path )
905- . digest ( 'hex' ) ;
920+ const hash = crypto . createHash ( 'md5' ) . update ( path ) . digest ( 'hex' ) ;
906921 slug = `#diff-${ hash } ${ side } ${ line } ` ;
907922 }
908923 // Mention the file and line number. If we can't get this for some reason then use the commit id instead.
0 commit comments