-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/getTarget
- Loading branch information
Showing
30 changed files
with
1,075 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { requestsManager } from 'snyk-request-manager'; | ||
import * as debugLib from 'debug'; | ||
|
||
const debug = debugLib('snyk:get-feature-flag'); | ||
|
||
export async function getFeatureFlag( | ||
requestManager: requestsManager, | ||
featureFlagName: string, | ||
orgId: string, | ||
): Promise<boolean> { | ||
debug( | ||
`Checking if feature flag ${featureFlagName} is enabled for Snyk org ${orgId}`, | ||
); | ||
try { | ||
const url = `cli-config/feature-flags/${featureFlagName}?org=${orgId}`; | ||
const res = await requestManager.request({ | ||
verb: 'get', | ||
url: url, | ||
useRESTApi: false, | ||
}); | ||
|
||
debug(`Feature flag ${featureFlagName} is enabled for Org ${orgId}`); | ||
|
||
const enabled: boolean = res.data['ok']; | ||
|
||
return enabled; | ||
} catch (err: any) { | ||
console.log(err.message) | ||
const res = err.message?.response?.data; | ||
const message = res?.userMessage || res?.message || err.message?.message; | ||
|
||
if (res && res.ok === false && res?.userMessage?.includes('feature enabled')) { | ||
debug( | ||
`Feature flag ${featureFlagName} is not enabled for Org ${orgId}`, | ||
); | ||
return false; | ||
} | ||
|
||
debug( | ||
`Could not fetch the ${featureFlagName} feature flag for ${orgId}\n ${JSON.stringify( | ||
err, | ||
)}`, | ||
); | ||
throw new Error(message); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { Octokit } from '@octokit/rest'; | ||
import * as debugLib from 'debug'; | ||
import type { Target } from '../../types'; | ||
import { getGithubToken } from './get-github-token'; | ||
import { getGithubBaseUrl } from './github-base-url'; | ||
|
||
const debug = debugLib('snyk:get-github-defaultBranch-script'); | ||
|
||
export async function getGithubReposDefaultBranch( | ||
RepoName: string, | ||
target: Target, | ||
host?: string, | ||
): Promise<string> { | ||
const githubToken = getGithubToken(); | ||
const baseUrl = getGithubBaseUrl(host); | ||
const octokit: Octokit = new Octokit({ baseUrl, auth: githubToken }); | ||
|
||
debug(`fetching the default branch for repo: ${RepoName}`); | ||
|
||
const response = await octokit.request(`GET /repos/${RepoName}`); | ||
debug(`fetching the default branch for repo: ${target.owner}/${target.name}`); | ||
|
||
const response = await octokit.repos.get({ | ||
owner: target.owner!, | ||
repo: target.name!, | ||
}); | ||
return response.data.default_branch as string; | ||
} |
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
Oops, something went wrong.