Skip to content

Commit

Permalink
Merge pull request #388 from snyk-tech-services/feat/return-ssh-url
Browse files Browse the repository at this point in the history
refactor: return sshUrl as well
  • Loading branch information
lili2311 authored Nov 28, 2022
2 parents 0bcfe7b + 85e458e commit 7195483
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/lib/source-handlers/github/get-repo-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from '@octokit/rest';
import * as debugLib from 'debug';
import type { Target } from '../../types';
import type { RepoMetaData, Target } from '../../types';
import { getGithubToken } from './get-github-token';
import { getGithubBaseUrl } from './github-base-url';

Expand All @@ -9,7 +9,7 @@ const debug = debugLib('snyk:get-github-defaultBranch-script');
export async function getGithubRepoMetaData(
target: Target,
host?: string,
): Promise<{ branch: string; cloneUrl: string }> {
): Promise<RepoMetaData> {
const githubToken = getGithubToken();
const baseUrl = getGithubBaseUrl(host);
const octokit: Octokit = new Octokit({ baseUrl, auth: githubToken });
Expand All @@ -23,5 +23,6 @@ export async function getGithubRepoMetaData(
return {
branch: response.data.default_branch!,
cloneUrl: response.data.clone_url!,
sshUrl: response.data.ssh_url!,
};
}
2 changes: 1 addition & 1 deletion src/lib/source-handlers/github/list-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Octokit } from '@octokit/rest';
import * as debugLib from 'debug';
import { getGithubToken } from './get-github-token';
import { getGithubBaseUrl } from './github-base-url';
import { GithubRepoData } from './types';
import type { GithubRepoData } from './types';

const debug = debugLib('snyk:list-repos-script');

Expand Down
6 changes: 6 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export interface SnykTargetRelationships {
};
}

export interface RepoMetaData {
branch: string;
cloneUrl: string;
sshUrl: string;
}

export interface SnykTarget {
attributes: {
displayName: string;
Expand Down
6 changes: 6 additions & 0 deletions test/scripts/sync/sync-org-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('updateTargets', () => {
Promise.resolve({
branch: defaultBranch,
cloneUrl: 'https://some-url.com',
sshUrl: '[email protected]',
}),
);
updateProjectsSpy.mockImplementation(() =>
Expand Down Expand Up @@ -185,6 +186,7 @@ describe('updateTargets', () => {
Promise.resolve({
branch: defaultBranch,
cloneUrl: 'https://some-url.com',
sshUrl: '[email protected]',
}),
);
updateProjectsSpy.mockImplementation(() =>
Expand Down Expand Up @@ -285,6 +287,7 @@ describe('updateTargets', () => {
Promise.resolve({
branch: defaultBranch,
cloneUrl: 'https://some-url.com',
sshUrl: '[email protected]',
}),
);
updateProjectsSpy
Expand Down Expand Up @@ -389,6 +392,7 @@ describe('updateTargets', () => {
Promise.resolve({
branch: defaultBranch,
cloneUrl: 'https://some-url.com',
sshUrl: '[email protected]',
}),
);
updateProjectsSpy
Expand Down Expand Up @@ -673,6 +677,7 @@ describe('updateOrgTargets', () => {
githubSpy.mockResolvedValue({
branch: defaultBranch,
cloneUrl: 'https://some-url.com',
sshUrl: '[email protected]',
});
const updated: syncProjectsForTarget.ProjectUpdate[] = [
{
Expand Down Expand Up @@ -820,6 +825,7 @@ describe('updateOrgTargets', () => {
githubSpy.mockResolvedValue({
branch: defaultBranch,
cloneUrl: 'https://some-url.com',
sshUrl: '[email protected]',
});
const updated: syncProjectsForTarget.ProjectUpdate[] = [
{
Expand Down

0 comments on commit 7195483

Please sign in to comment.