Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reviewers config #36

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __snapshots__/bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ exports['Bootstrapper should open a PR 1'] = `
"release-type": "node"
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
"$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json"
}
`
5 changes: 5 additions & 0 deletions __snapshots__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Options:
--signoff Add Signed-off-by line at the end of the commit log
message using the user and email provided. (format "Name
<email@example.com>"). [string]
--reviewers Github usernames that should be assigned as reviewers to
the release pull request [string]
--config-file where can the config file be found in the project?
[default: "release-please-config.json"]
--manifest-file where can the manifest file be found in the project?
Expand Down Expand Up @@ -248,6 +250,9 @@ Options:
commit log message using the user and email
provided. (format "Name
<email@example.com>"). [string]
--reviewers Github usernames that should be assigned as
reviewers to the release pull request
[string]
--include-v-in-tags include "v" in tag versions
[boolean] [default: true]
--monorepo-tags include library name in tags and release
Expand Down
8 changes: 8 additions & 0 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@
"description": "Customize the separator between the component and version in the GitHub tag.",
"type": "string"
},
"reviewers": {
"description": "Github usernames that should be assigned as reviewers to the release pull request",
"type": "array",
"items": {
"type": "string"
}
},
"extra-files": {
"description": "Specify extra generic files to replace versions.",
"type": "array",
Expand Down Expand Up @@ -443,6 +450,7 @@
"separate-pull-requests": true,
"tag-separator": true,
"extra-files": true,
"reviewers": true,
"version-file": true,
"snapshot-label": true,
"initial-version": true,
Expand Down
16 changes: 16 additions & 0 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ interface PullRequestArgs {
label?: string;
skipLabeling?: boolean;
signoff?: string;
reviewers?: string[];
}

interface PullRequestStrategyArgs {
Expand Down Expand Up @@ -273,6 +274,17 @@ function pullRequestOptions(yargs: yargs.Argv): yargs.Argv {
describe:
'Add Signed-off-by line at the end of the commit log message using the user and email provided. (format "Name <email@example.com>").',
type: 'string',
})
.option('reviewers', {
describe:
'Github usernames that should be assigned as reviewers to the release pull request',
type: 'string',
coerce(arg?: string) {
if (arg) {
return arg.split(',');
}
return arg;
},
});
}

Expand Down Expand Up @@ -479,6 +491,7 @@ const createReleasePullRequestCommand: yargs.CommandModule<
versionFile: argv.versionFile,
includeComponentInTag: argv.monorepoTags,
includeVInTag: argv.includeVInTags,
reviewers: argv.reviewers,
},
extractManifestOptions(argv),
argv.path
Expand Down Expand Up @@ -885,6 +898,9 @@ function extractManifestOptions(
if ('fork' in argv && argv.fork !== undefined) {
manifestOptions.fork = argv.fork;
}
if ('reviewers' in argv && argv.reviewers) {
manifestOptions.reviewers = argv.reviewers;
}
if (argv.label !== undefined) {
let labels: string[] = argv.label.split(',');
if (labels.length === 1 && labels[0] === '') labels = [];
Expand Down
16 changes: 10 additions & 6 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,21 @@ export type ChangeSet = Map<string, FileDiff>;
interface CreatePullRequestOptions {
fork?: boolean;
draft?: boolean;
reviewers?: [string];
reviewers?: string[];
/**
* If the number of an existing pull request is passed, its HEAD branch and attributes (title, labels, etc) will be
* updated instead of creating a new pull request.
*/
existingPrNumber?: number;
}

interface UpdatePullRequestOptions {
signoffUser?: string;
fork?: boolean;
reviewers?: string[];
pullRequestOverflowHandler?: PullRequestOverflowHandler;
}

export class GitHub {
readonly repository: Repository;
private octokit: OctokitType;
Expand Down Expand Up @@ -1397,11 +1404,7 @@ export class GitHub {
releasePullRequest: ReleasePullRequest,
baseBranch: string,
refBranch: string,
options?: {
signoffUser?: string;
fork?: boolean;
pullRequestOverflowHandler?: PullRequestOverflowHandler;
}
options?: UpdatePullRequestOptions
): Promise<PullRequest> => {
// Update the files for the release if not already supplied
let message = releasePullRequest.title.toString();
Expand Down Expand Up @@ -1435,6 +1438,7 @@ export class GitHub {
releasePullRequest.updates,
{
fork: options?.fork,
reviewers: options?.reviewers,
existingPrNumber: number,
}
);
Expand Down
14 changes: 11 additions & 3 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface ReleaserConfig {
skipSnapshot?: boolean;
// Manifest only
excludePaths?: string[];
reviewers?: string[];
}

export interface CandidateReleasePullRequest {
Expand Down Expand Up @@ -176,6 +177,7 @@ interface ReleaserConfigJson {
'skip-snapshot'?: boolean; // Java-only
'initial-version'?: string;
'exclude-paths'?: string[]; // manifest-only
reviewers?: string[];
}

export interface ManifestOptions {
Expand All @@ -185,6 +187,7 @@ export interface ManifestOptions {
separatePullRequests?: boolean;
plugins?: PluginType[];
fork?: boolean;
reviewers?: string[];
signoff?: string;
manifestPath?: string;
labels?: string[];
Expand Down Expand Up @@ -289,6 +292,7 @@ export class Manifest {
readonly changesBranch: string;
private separatePullRequests: boolean;
readonly fork: boolean;
private reviewers: string[];
private signoffUser?: string;
private labels: string[];
private skipLabeling?: boolean;
Expand Down Expand Up @@ -357,6 +361,7 @@ export class Manifest {
manifestOptions?.separatePullRequests ??
Object.keys(repositoryConfig).length === 1;
this.fork = manifestOptions?.fork || false;
this.reviewers = manifestOptions?.reviewers ?? [];
this.signoffUser = manifestOptions?.signoff;
this.releaseLabels =
manifestOptions?.releaseLabels || DEFAULT_RELEASE_LABELS;
Expand Down Expand Up @@ -1034,6 +1039,7 @@ export class Manifest {
{
fork: this.fork,
draft: pullRequest.draft,
reviewers: this.reviewers,
}
);

Expand Down Expand Up @@ -1063,6 +1069,7 @@ export class Manifest {
this.changesBranch,
{
fork: this.fork,
reviewers: this.reviewers,
signoffUser: this.signoffUser,
pullRequestOverflowHandler: this.pullRequestOverflowHandler,
}
Expand Down Expand Up @@ -1574,6 +1581,7 @@ function extractReleaserConfig(
skipSnapshot: config['skip-snapshot'],
initialVersion: config['initial-version'],
excludePaths: config['exclude-paths'],
reviewers: config.reviewers,
};
}

Expand Down Expand Up @@ -1611,8 +1619,7 @@ async function parseConfig(
const configReleaseLabel = config['release-label'];
const configPreReleaseLabel = config['prerelease-label'];
const configSnapshotLabel = config['snapshot-label'];
const configExtraLabel = config['extra-label'];
const manifestOptions = {
const manifestOptions: ManifestOptions = {
bootstrapSha: config['bootstrap-sha'],
lastReleaseSha: config['last-release-sha'],
alwaysLinkLocal: config['always-link-local'],
Expand All @@ -1623,10 +1630,10 @@ async function parseConfig(
releaseLabels: configReleaseLabel?.split(','),
prereleaseLabels: configPreReleaseLabel?.split(','),
snapshotLabels: configSnapshotLabel?.split(','),
extraLabels: configExtraLabel?.split(','),
releaseSearchDepth: config['release-search-depth'],
commitSearchDepth: config['commit-search-depth'],
sequentialCalls: config['sequential-calls'],
reviewers: config.reviewers,
};
return {config: repositoryConfig, options: manifestOptions};
}
Expand Down Expand Up @@ -1925,6 +1932,7 @@ function mergeReleaserConfig(
initialVersion: pathConfig.initialVersion ?? defaultConfig.initialVersion,
extraLabels: pathConfig.extraLabels ?? defaultConfig.extraLabels,
excludePaths: pathConfig.excludePaths ?? defaultConfig.excludePaths,
reviewers: pathConfig.reviewers ?? defaultConfig.reviewers,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/updaters/release-please-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '../manifest';

const SCHEMA_URL =
'https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json';
'https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json';

interface ManifestConfigFile extends ManifestConfig {
$schema?: string;
Expand Down Expand Up @@ -80,7 +80,7 @@ function releaserConfigToJsonConfig(
'tag-separator': config.tagSeparator,
'extra-files': config.extraFiles,
'version-file': config.versionFile,
'snapshot-label': config.snapshotLabels?.join(','), // Java-only
'snapshot-label': config.snapshotLabels?.join(','), // Java-only,
};
return jsonConfig;
}
48 changes: 27 additions & 21 deletions test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,6 @@ import {ParseCallback} from 'yargs';

const sandbox = sinon.createSandbox();

// function callStub(
// instance: Manifest,
// method: ManifestMethod
// ): ManifestCallResult;
// function callStub(
// instance: ReleasePR,
// method: ReleasePRMethod
// ): ReleasePRCallResult;
// function callStub(
// instance: GitHubRelease,
// method: GitHubReleaseMethod
// ): GitHubReleaseCallResult;
// function callStub(
// instance: Manifest | ReleasePR | GitHubRelease,
// method: Method
// ): CallResult {
// instanceToRun = instance;
// methodCalled = method;
// return Promise.resolve(undefined);
// }

describe('CLI', () => {
let fakeGitHub: GitHub;
let fakeManifest: Manifest;
Expand Down Expand Up @@ -665,6 +644,7 @@ describe('CLI', () => {
);
sinon.assert.calledOnce(createPullRequestsStub);
});

for (const flag of ['--target-branch', '--default-branch']) {
it(`handles ${flag}`, async () => {
await parser.parseAsync(
Expand Down Expand Up @@ -1243,6 +1223,32 @@ describe('CLI', () => {
);
sinon.assert.calledOnce(createPullRequestsStub);
});

it('handles --reviewers', async () => {
await parser.parseAsync(
'release-pr --repo-url=googleapis/release-please-cli --release-type=java-yoshi --reviewers=sam,frodo'
);

sinon.assert.calledOnceWithExactly(gitHubCreateStub, {
owner: 'googleapis',
repo: 'release-please-cli',
token: undefined,
apiUrl: 'https://api.github.com',
graphqlUrl: 'https://api.github.com',
useGraphql: true,
retries: 3,
throttlingRetries: 3,
});
sinon.assert.calledOnceWithExactly(
fromConfigStub,
fakeGitHub,
'main',
sinon.match({releaseType: 'java-yoshi', reviewers: ['sam', 'frodo']}),
sinon.match({}),
undefined
);
sinon.assert.calledOnce(createPullRequestsStub);
});
});
});
describe('github-release', () => {
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/manifest/config/reviewers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"release-type": "simple",
"packages": {
".": {
"component": "root"
}
},
"reviewers": [
"sam",
"frodo"
]
}
28 changes: 28 additions & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,34 @@ describe('Manifest', () => {
'custom: pre-release',
]);
});

it('should read reviewers from manifest', async () => {
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('release-please-config.json', 'next')
.resolves(
buildGitHubFileContent(fixturesPath, 'manifest/config/reviewers.json')
)
.withArgs('.release-please-manifest.json', 'next')
.resolves(
buildGitHubFileContent(
fixturesPath,
'manifest/versions/versions.json'
)
);
const manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch,
undefined,
undefined,
{changesBranch: 'next'}
);
expect(manifest['reviewers']).to.deep.equal(['sam', 'frodo']);
});

it('should read extra labels from manifest', async () => {
const getFileContentsStub = sandbox.stub(
github,
Expand Down
Loading