Skip to content

Commit

Permalink
fix: init octokit for all functions in github api (#3119)
Browse files Browse the repository at this point in the history
  • Loading branch information
VonnyJap authored May 13, 2024
1 parent ac35b12 commit 3a9fc4f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion features/step_definitions/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Before(
tags: '@subscribe'
},
function hook() {
github.getOctokit();
this.repoOrg = this.testOrg;
this.pipelines = {};
this.pipelineId = null;
Expand Down
25 changes: 23 additions & 2 deletions features/support/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function cleanUpRepository(branch, tags, repoOwner, repoName) {
ref: `heads/${branch}`
};

octokit = getOctokit();

const removeTagPromises = tags.map(tag => {
const tagParams = {
owner: repoOwner,
Expand Down Expand Up @@ -90,6 +92,8 @@ function removeBranch(repoOwner, repoName, branchName) {
ref: `heads/${branchName}`
};

octokit = getOctokit();

return octokit.git.getRef(branchParams).then(() => octokit.git.deleteRef(branchParams));
}

Expand All @@ -102,6 +106,8 @@ function removeBranch(repoOwner, repoName, branchName) {
* @return {Promise}
*/
function closePullRequest(repoOwner, repoName, prNumber) {
octokit = getOctokit();

return octokit.pulls.update({
owner: repoOwner,
repo: repoName,
Expand All @@ -122,6 +128,8 @@ function createBranch(branch, repoOwner, repoName, ref = 'heads/master') {
const owner = repoOwner || 'screwdriver-cd-test';
const repo = repoName || 'functional-git';

octokit = getOctokit();

return octokit.git
.getRef({
owner,
Expand Down Expand Up @@ -163,6 +171,8 @@ function createFile(branch, repoOwner, repoName, directoryName, commitMessage) {
const filePath = directoryName || 'testfiles';
const message = commitMessage || new Date().toString(); // default commit message is the current time

octokit = getOctokit();

return octokit.repos.createOrUpdateFileContents({
owner,
repo,
Expand All @@ -183,6 +193,8 @@ function createFile(branch, repoOwner, repoName, directoryName, commitMessage) {
* @return {Promise}
*/
function createPullRequest(sourceBranch, targetBranch, repoOwner, repoName) {
octokit = getOctokit();

return octokit.pulls.create({
owner: repoOwner,
repo: repoName,
Expand All @@ -205,6 +217,8 @@ function createTag(tag, branch, repoOwner, repoName) {
const owner = repoOwner || 'screwdriver-cd-test';
const repo = repoName || 'functional-git';

octokit = getOctokit();

return octokit.git
.getRef({
owner,
Expand Down Expand Up @@ -239,6 +253,8 @@ function createAnnotatedTag(tag, branch, repoOwner, repoName) {
const owner = repoOwner || 'screwdriver-cd-test';
const repo = repoName || 'functional-git';

octokit = getOctokit();

return octokit.git
.getRef({
owner,
Expand Down Expand Up @@ -289,6 +305,8 @@ function createRelease(tagName, repoOwner, repoName) {
const owner = repoOwner || 'screwdriver-cd-test';
const repo = repoName || 'functional-git';

octokit = getOctokit();

return octokit.repos
.createRelease({
owner,
Expand All @@ -311,6 +329,8 @@ function createRelease(tagName, repoOwner, repoName) {
* @return {Promise}
*/
function getStatus(repoOwner, repoName, sha) {
octokit = getOctokit();

return octokit.repos.getCombinedStatusForRef({
owner: repoOwner,
repo: repoName,
Expand All @@ -327,6 +347,8 @@ function getStatus(repoOwner, repoName, sha) {
* @return {Promise}
*/
function mergePullRequest(repoOwner, repoName, prNumber) {
octokit = getOctokit();

return octokit.pulls.merge({
owner: repoOwner,
repo: repoName,
Expand All @@ -345,6 +367,5 @@ module.exports = {
createRelease,
getStatus,
mergePullRequest,
removeBranch,
getOctokit
removeBranch
};
4 changes: 2 additions & 2 deletions test/plugins/webhooks.helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ describe('startHookEvent test', () => {
branch: Promise.resolve('master')
})
]);
const pipelineMock2 = Object.assign({}, pipelineMock);
const pipelineMock2 = { ...pipelineMock };

pipelineMock2.subscribedScmUrlsWithActions = [{ scmUri: 'github.com:789123:master', actions: ['commit'] }];
pipelineFactoryMock.list
Expand Down Expand Up @@ -2008,7 +2008,7 @@ describe('startHookEvent test', () => {
branch: Promise.resolve('master')
})
]);
const pipelineMock2 = Object.assign({}, pipelineMock);
const pipelineMock2 = { ...pipelineMock };

pipelineMock2.subscribedScmUrlsWithActions = [{ scmUri: 'github.com:789123:master', actions: ['pr'] }];
pipelineFactoryMock.list
Expand Down

0 comments on commit 3a9fc4f

Please sign in to comment.