Skip to content

Commit

Permalink
Changes pr id be a string to be more flexible
Browse files Browse the repository at this point in the history
Renames pr.number to pr.id
  • Loading branch information
eamodio committed Nov 29, 2020
1 parent e76bca8 commit 511894a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
10 changes: 5 additions & 5 deletions src/git/formatters/commitFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
const { pullRequestOrRemote: pr } = this._options;
if (pr != null) {
if (PullRequest.is(pr)) {
commands += `[$(git-pull-request) PR #${pr.number}](${pr.url} "Open Pull Request \\#${pr.number} on ${
commands += `[$(git-pull-request) PR #${pr.id}](${pr.url} "Open Pull Request \\#${pr.id} on ${
pr.provider
}\n${GlyphChars.Dash.repeat(2)}\n${pr.title}\n${pr.state}, ${pr.formatDateFromNow()}")${separator}`;
} else if (pr instanceof Promises.CancellationError) {
Expand Down Expand Up @@ -456,19 +456,19 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
let text;
if (PullRequest.is(pr)) {
if (this._options.markdown) {
text = `[PR #${pr.number}](${pr.url} "Open Pull Request \\#${pr.number} on ${
text = `[PR #${pr.id}](${pr.url} "Open Pull Request \\#${pr.id} on ${
pr.provider
}\n${GlyphChars.Dash.repeat(2)}\n${pr.title}\n${pr.state}, ${pr.formatDateFromNow()}")`;
} else if (this._options.footnotes != null) {
const index = this._options.footnotes.size + 1;
this._options.footnotes.set(
index,
`PR #${pr.number}: ${pr.title} ${GlyphChars.Dot} ${pr.state}, ${pr.formatDateFromNow()}`,
`PR #${pr.id}: ${pr.title} ${GlyphChars.Dot} ${pr.state}, ${pr.formatDateFromNow()}`,
);

text = `PR #${pr.number}${Strings.getSuperscript(index)}`;
text = `PR #${pr.id}${Strings.getSuperscript(index)}`;
} else {
text = `PR #${pr.number}`;
text = `PR #${pr.id}`;
}
} else if (pr instanceof Promises.CancellationError) {
text = this._options.markdown
Expand Down
2 changes: 1 addition & 1 deletion src/git/models/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class PullRequest {
readonly avatarUrl: string;
readonly url: string;
},
public readonly number: number,
public readonly id: string,
public readonly title: string,
public readonly url: string,
public readonly state: PullRequestState,
Expand Down
23 changes: 2 additions & 21 deletions src/github/github.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { graphql } from '@octokit/graphql';
import { Logger } from '../logger';
import { debug, Functions } from '../system';
import { debug } from '../system';
import { AuthenticationError, ClientError, IssueOrPullRequest, PullRequest, PullRequestState } from '../git/git';
import { Account } from '../git/models/author';

Expand Down Expand Up @@ -340,25 +340,6 @@ export class GitHubApi {
avatarSize?: number;
},
): Promise<PullRequest | undefined> {
if (ref === 'b44296e7c45a9e83530feb976f9f293a78457161') {
await Functions.wait(5000);
return new PullRequest(
provider,
{
name: 'Eric Amodio',
avatarUrl: `https://avatars1.githubusercontent.com/u/641685?s=${options?.avatarSize ?? 32}&v=4`,
url: 'https://github.com/eamodio',
},
1,
'Supercharged',
'https://github.com/eamodio/vscode-gitlens/pulls/1',
PullRequestState.Merged,
new Date('Sat, 12 Nov 2016 19:41:00 GMT'),
undefined,
new Date('Sat, 12 Nov 2016 20:41:00 GMT'),
);
}

const cc = Logger.getCorrelationContext();

try {
Expand Down Expand Up @@ -478,7 +459,7 @@ export namespace GitHubPullRequest {
avatarUrl: pr.author.avatarUrl,
url: pr.author.url,
},
pr.number,
String(pr.number),
pr.title,
pr.permalink,
fromState(pr.state),
Expand Down
15 changes: 6 additions & 9 deletions src/views/nodes/pullRequestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class PullRequestNode extends ViewNode<
BranchesView | CommitsView | ContributorsView | RemotesView | RepositoriesView | SearchAndCompareView
> {
static key = ':pullrequest';
static getId(repoPath: string, number: number, ref: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${number}):${ref}`;
static getId(repoPath: string, id: string, ref: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${id}):${ref}`;
}

constructor(
Expand All @@ -33,28 +33,25 @@ export class PullRequestNode extends ViewNode<
}

get id(): string {
return PullRequestNode.getId(this.branchOrCommit.repoPath, this.pullRequest.number, this.branchOrCommit.ref);
return PullRequestNode.getId(this.branchOrCommit.repoPath, this.pullRequest.id, this.branchOrCommit.ref);
}

getChildren(): ViewNode[] {
return [];
}

getTreeItem(): TreeItem {
const item = new TreeItem(
`#${this.pullRequest.number}: ${this.pullRequest.title}`,
TreeItemCollapsibleState.None,
);
const item = new TreeItem(`#${this.pullRequest.id}: ${this.pullRequest.title}`, TreeItemCollapsibleState.None);
item.contextValue = ContextValues.PullRequest;
item.description = `${this.pullRequest.state}, ${this.pullRequest.formatDateFromNow()}`;
item.iconPath = new ThemeIcon('git-pull-request');
item.id = this.id;
item.tooltip = `${this.pullRequest.title}\n#${this.pullRequest.number} by ${this.pullRequest.author.name} was ${
item.tooltip = `${this.pullRequest.title}\n#${this.pullRequest.id} by ${this.pullRequest.author.name} was ${
this.pullRequest.state === PullRequestState.Open ? 'opened' : this.pullRequest.state.toLowerCase()
} ${this.pullRequest.formatDateFromNow()}`;

if (this.branchOrCommit instanceof GitCommit) {
item.tooltip = `Commit ${this.branchOrCommit.shortSha} was introduced by PR #${this.pullRequest.number}\n${item.tooltip}`;
item.tooltip = `Commit ${this.branchOrCommit.shortSha} was introduced by PR #${this.pullRequest.id}\n${item.tooltip}`;
}

// item.tooltip = `Open Pull Request #${this.pullRequest.number} on ${this.pullRequest.provider}`;
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/webviewBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export abstract class WebviewBase implements Disposable {
avatarUrl: 'https://avatars1.githubusercontent.com/u/641685?s=32&v=4',
url: 'https://github.com/eamodio',
},
1,
'1',
'Supercharged',
'https://github.com/eamodio/vscode-gitlens/pulls/1',
PullRequestState.Merged,
Expand Down

0 comments on commit 511894a

Please sign in to comment.