Skip to content

Commit

Permalink
feat: create a function to get the github default branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mathild3r committed Oct 11, 2022
1 parent 2fcb103 commit 74897ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib/source-handlers/github/get-default-branch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Octokit } from '@octokit/rest';
import * as debugLib from 'debug';
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,
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}`)

return response.data.default_branch as string

}
1 change: 1 addition & 0 deletions src/lib/source-handlers/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './list-organizations';
export * from './list-repos';
export * from './organization-is-empty';
export * from './get-default-branch';
export * from './types';

0 comments on commit 74897ba

Please sign in to comment.