-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
157 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios from 'axios'; | ||
import { BackportOptions } from '../../../options/options'; | ||
import { addAssigneesToPullRequest } from './addAssigneesToPullRequest'; | ||
|
||
describe('addAssigneesToPullRequest', () => { | ||
it('should add assignees to PR', async () => { | ||
const pullNumber = 216; | ||
const assignees = ['sqren']; | ||
|
||
const spy = jest | ||
.spyOn(axios, 'request') | ||
.mockResolvedValueOnce('some-response'); | ||
|
||
await addAssigneesToPullRequest( | ||
{ | ||
githubApiBaseUrlV3: 'https://api.github.com', | ||
repoName: 'backport-demo', | ||
repoOwner: 'sqren', | ||
accessToken: 'my-token', | ||
username: 'sqren', | ||
dryRun: false, | ||
} as BackportOptions, | ||
pullNumber, | ||
assignees | ||
); | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
method: 'post', | ||
url: | ||
'https://api.github.com/repos/sqren/backport-demo/issues/216/assignees', | ||
auth: { username: 'sqren', password: 'my-token' }, | ||
data: { assignees: ['sqren'] }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import ora from 'ora'; | ||
import { BackportOptions } from '../../../options/options'; | ||
import { logger } from '../../logger'; | ||
import { apiRequestV3 } from './apiRequestV3'; | ||
|
||
export async function addAssigneesToPullRequest( | ||
{ | ||
githubApiBaseUrlV3, | ||
repoName, | ||
repoOwner, | ||
accessToken, | ||
username, | ||
dryRun, | ||
}: BackportOptions, | ||
pullNumber: number, | ||
assignees: string[] | ||
): Promise<void> { | ||
const isSelfAssigning = assignees.length === 1 && assignees[0] === username; | ||
|
||
const text = isSelfAssigning | ||
? `Self-assigning to #${pullNumber}` | ||
: `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`; | ||
logger.info(text); | ||
const spinner = ora(text).start(); | ||
|
||
try { | ||
if (dryRun) { | ||
spinner.succeed(`Dry run: ${text}`); | ||
return; | ||
} | ||
|
||
await apiRequestV3({ | ||
method: 'post', | ||
url: `${githubApiBaseUrlV3}/repos/${repoOwner}/${repoName}/issues/${pullNumber}/assignees`, | ||
data: { assignees }, | ||
auth: { | ||
username: username, | ||
password: accessToken, | ||
}, | ||
}); | ||
spinner.succeed(); | ||
} catch (e) { | ||
spinner.fail(); | ||
logger.info(`Could not add assignees to PR ${pullNumber}`, e.stack); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters