Skip to content

Commit

Permalink
Introduce branch on repo targets
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Dec 20, 2018
1 parent 9287ab8 commit 6b0705b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
4 changes: 1 addition & 3 deletions lib/internal/transport/websocket/WebSocketLifecycle.ts
Expand Up @@ -70,9 +70,7 @@ export class WebSocketLifecycle {
while (this.messages.length) {
queuedMessages.push(this.messages.pop());
}
for (const queuedMessage of queuedMessages) {
await this.send(queuedMessage);
}
queuedMessages.forEach(this.send);
}, 1000);
this.timer.unref();
}
Expand Down
6 changes: 5 additions & 1 deletion lib/operations/common/params/AlwaysAskRepoParameters.ts
Expand Up @@ -6,6 +6,7 @@ import { GitHubTargetsParams } from "./GitHubTargetsParams";
import {
GitBranchRegExp,
GitHubNameRegExp,
GitShaRegExp,
} from "./validationPatterns";

/**
Expand All @@ -21,7 +22,10 @@ export class AlwaysAskRepoParameters extends GitHubTargetsParams {
@Parameter({ description: "Name of repo to edit or regex", pattern: /.+/, required: true })
public repo: string;

@Parameter({ description: "Branch or ref. Defaults to 'master'", ...GitBranchRegExp, required: false })
@Parameter({ description: "Ref", ...GitShaRegExp, required: false })
public sha: string;

@Parameter({ description: "Branch Defaults to 'master'", ...GitBranchRegExp, required: false })
public branch: string = "master";

}
12 changes: 9 additions & 3 deletions lib/operations/common/params/GitHubFallbackReposParameters.ts
Expand Up @@ -5,7 +5,10 @@ import {
} from "../../../decorators";
import { FallbackParams } from "./FallbackParams";
import { GitHubTargetsParams } from "./GitHubTargetsParams";
import { GitBranchRegExp } from "./validationPatterns";
import {
GitBranchRegExp,
GitShaRegExp,
} from "./validationPatterns";

/**
* Resolve from a Mapped parameter or from a supplied repos regex if no repo mapping
Expand All @@ -18,8 +21,11 @@ export class GitHubFallbackReposParameters extends GitHubTargetsParams implement
@MappedParameter(MappedParameters.GitHubRepository, false)
public repo: string;

@Parameter({ description: "Branch or ref. Defaults to 'master'", ...GitBranchRegExp, required: false })
public sha: string = "master";
@Parameter({ description: "Ref", ...GitShaRegExp, required: false })
public sha: string;

@Parameter({ description: "Branch Defaults to 'master'", ...GitBranchRegExp, required: false })
public branch: string = "master";

@Parameter({ description: "regex", required: false })
public repos: string = ".*";
Expand Down
18 changes: 7 additions & 11 deletions lib/operations/common/params/GitHubTargetsParams.ts
Expand Up @@ -32,20 +32,16 @@ export abstract class GitHubTargetsParams extends TargetsParams {
if (!this.owner || !this.repo || this.usesRegex) {
return undefined;
}
// sha is actually a ref (either sha or pointer)
const branch = isValidSHA1(this.sha) ? undefined : this.sha;
const sha = isValidSHA1(this.sha) ? this.sha : undefined;
return GitHubRepoRef.from({ owner: this.owner, repo: this.repo, sha, branch, rawApiBase: this.apiUrl });
return GitHubRepoRef.from({
owner: this.owner,
repo: this.repo,
sha: this.sha,
branch: this.branch,
rawApiBase: this.apiUrl,
});
}

@Secret(Secrets.userToken(["repo", "user:email", "read:user"]))
private githubToken: string;

}

function isValidSHA1(s: string): boolean {
if (!s) {
return false;
}
return s.match(/[a-fA-F0-9]{40}/) != null;
}
17 changes: 10 additions & 7 deletions lib/operations/common/params/GitlabTargetsParams.ts
Expand Up @@ -9,7 +9,10 @@ import { GitlabPrivateTokenCredentials } from "../GitlabPrivateTokenCredentials"
import { GitlabRepoRef } from "../GitlabRepoRef";
import { ProjectOperationCredentials } from "../ProjectOperationCredentials";
import { TargetsParams } from "./TargetsParams";
import { GitBranchRegExp } from "./validationPatterns";
import {
GitBranchRegExp,
GitShaRegExp,
} from "./validationPatterns";

@Parameters()
export class GitlabTargetsParams extends TargetsParams {
Expand All @@ -26,12 +29,11 @@ export class GitlabTargetsParams extends TargetsParams {
@MappedParameter(MappedParameters.GitHubUrl, false)
public url: string;

@Parameter({
description: "Branch or ref. Defaults to 'master'",
...GitBranchRegExp,
required: false,
})
public sha: string = "master";
@Parameter({ description: "Ref", ...GitShaRegExp, required: false })
public sha: string;

@Parameter({ description: "Branch Defaults to 'master'", ...GitBranchRegExp, required: false })
public branch: string = "master";

@Parameter({ description: "regex", required: false })
public repos: string = ".*";
Expand Down Expand Up @@ -62,6 +64,7 @@ export class GitlabTargetsParams extends TargetsParams {
owner: this.owner,
repo: this.repo,
sha: this.sha,
branch: this.branch,
rawApiBase: this.apiUrl,
gitlabRemoteUrl: this.url,
}) :
Expand Down
10 changes: 8 additions & 2 deletions lib/operations/common/params/MappedRepoParameters.ts
Expand Up @@ -5,7 +5,10 @@ import {
Parameters,
} from "../../../decorators";
import { GitHubTargetsParams } from "./GitHubTargetsParams";
import { GitBranchRegExp } from "./validationPatterns";
import {
GitBranchRegExp,
GitShaRegExp,
} from "./validationPatterns";

/**
* Get target from channel mapping
Expand All @@ -19,7 +22,10 @@ export class MappedRepoParameters extends GitHubTargetsParams {
@MappedParameter(MappedParameters.GitHubRepository)
public repo: string;

@Parameter({ description: "Branch or ref. Defaults to 'master'", ...GitBranchRegExp, required: false })
@Parameter({ description: "Ref", ...GitShaRegExp, required: false })
public sha: string;

@Parameter({ description: "Branch Defaults to 'master'", ...GitBranchRegExp, required: false })
public branch: string = "master";

}
2 changes: 2 additions & 0 deletions lib/operations/common/params/TargetsParams.ts
Expand Up @@ -23,6 +23,8 @@ export abstract class TargetsParams implements Credentialed, RemoteLocator {

public abstract sha;

public abstract branch;

public abstract credentials: ProjectOperationCredentials;

get usesRegex() {
Expand Down
3 changes: 1 addition & 2 deletions lib/operations/edit/editModes.ts
Expand Up @@ -104,8 +104,7 @@ export class PullRequest extends Commit {
public title: string,
public body: string = title,
public message: string = title,
// Make default to master for backwards-compatible reasons
public targetBranch: string = "master",
public targetBranch?: string,
public autoMerge?: AutoMerge) {
super(branch, message, autoMerge);
}
Expand Down

0 comments on commit 6b0705b

Please sign in to comment.