Skip to content

feat(owlbot-bootstrapper): get full mono repo path, mono repo name, and mono repo org from the cli args#4577

Merged
sofisl merged 13 commits into
mainfrom
getFullMonoRepoPath
Nov 1, 2022
Merged

feat(owlbot-bootstrapper): get full mono repo path, mono repo name, and mono repo org from the cli args#4577
sofisl merged 13 commits into
mainfrom
getFullMonoRepoPath

Conversation

@sofisl

@sofisl sofisl commented Oct 15, 2022

Copy link
Copy Markdown
Contributor

This PR adds in an argument to the owlbot-bootstrapper, the full mono-repo path, prompted by:

Should this include the repo name so I can `cd "${MONO_REPO_PATH}"` in my container? Otherwise, to be re-usable, you need to parse the `REPO_TO_CLONE` env to grab the repo name and then cd into that parsed value (or hard-code the repo name into the container).

Since the CLI should only receive the directory in which to clone the mono repo, and the ssh address of the mono repo to clone, this PR does the following things:

  1. Parses the repoToClone ssh address to get the mono repo name; then concatenates it to the monoRepoDir, which is the actual cli input. Then, throughout the rest of the process, we pass through the monoRepoDir, and the monoRepoPath. Language containers will only see the monoRepoPath.

  2. Since we're already parsing the repoToClone ssh address, I'm removing where we do that in the common container, and instead passing through the parsed variables (monoRepoName and monoRepoOrg). This standardizes the regex matching we're doing as well.

Instructions updated in cl/481195940

@sofisl sofisl requested a review from a team October 15, 2022 22:23
@sofisl sofisl changed the title Get full mono repo path feat: get full mono-repo path, mono repo name, and mono repo org from the cli args Oct 15, 2022
@sofisl sofisl changed the title feat: get full mono-repo path, mono repo name, and mono repo org from the cli args feat(owlbot-bootstrapper): get full mono repo path, mono repo name, and mono repo org from the cli args Oct 15, 2022
throw new Error('No language-specific container specified');
}

export function getMonoRepoNameAndOrg(repoToClone: string | undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define the return type explicitly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is probably better named as parseRepoNameAndOrg or parseGitHubRepository as the fact that it's a mono-repo is irrelevant.

export async function runTrigger(
argv: CliArgs,
cb: CloudBuildClient,
monoRepoNameAndOrg: {monoRepoName: string; monoRepoOrg: string},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type could be re-used. Additionally, the monoRepo part could be redundant.

Consider a type like:

interface GitHubRepository {
  owner: string;
  name: string;
}

Comment on lines +166 to +191
it('gets the correct mono repo name, or throws an error', () => {
assert.deepStrictEqual(
runTriggerCommand.getMonoRepoNameAndOrg(
'git@github.com:googleapis/google-cloud-node.git'
),
{monoRepoOrg: 'googleapis', monoRepoName: 'google-cloud-node'}
);

assert.deepStrictEqual(
runTriggerCommand.getMonoRepoNameAndOrg(
'git@github.com/googleapis/google-cloud-node.git'
),
{monoRepoOrg: 'googleapis', monoRepoName: 'google-cloud-node'}
);

assert.deepStrictEqual(
runTriggerCommand.getMonoRepoNameAndOrg(
'git@github.com:googleapis/nodejs-scheduler.git'
),
{monoRepoOrg: 'googleapis', monoRepoName: 'nodejs-scheduler'}
);

assert.throws(() => {
runTriggerCommand.getMonoRepoNameAndOrg(undefined);
}, new Error("Repo to clone arg is malformed; should be in form of ssh address,' git@github.com:googleapis/google-cloud-node.git'"));
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put these in a separate describe('getMonoRepoNameAndOrg') block

@sofisl sofisl requested a review from chingor13 November 1, 2022 17:36
);
});

describe('get mono repo name and org from ssh address', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would just name this describe block the exported function name being tested

This lets you easily run the subset of tests:

npm t -- -g 'parseRepoNameAndOrg'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants