Skip to content

Commit 0f1f855

Browse files
committed
Avoids attempting to get PR for uncommitted
1 parent 6546e74 commit 0f1f855

File tree

9 files changed

+36
-34
lines changed

9 files changed

+36
-34
lines changed

src/git/models/commit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,14 @@ export class GitCommit implements GitRevisionReference {
480480
remote?: GitRemote<RemoteProvider>,
481481
options?: { expiryOverride?: boolean | number },
482482
): Promise<PullRequest | undefined> {
483+
if (this.isUncommitted) return undefined;
484+
483485
remote ??= await this.container.git.remotes(this.repoPath).getBestRemoteWithIntegration();
484486
if (!remote?.hasIntegration()) return undefined;
485487

486488
return (await this.container.integrations.getByRemote(remote))?.getPullRequestForCommit(
487489
remote.provider.repoDesc,
488-
this.ref,
490+
this.sha,
489491
options,
490492
);
491493
}

src/plus/integrations/integration.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ export abstract class HostingIntegration<
729729
@debug()
730730
async getAccountForCommit(
731731
repo: T,
732-
ref: string,
732+
rev: string,
733733
options?: {
734734
avatarSize?: number;
735735
},
@@ -740,7 +740,7 @@ export abstract class HostingIntegration<
740740
if (!connected) return undefined;
741741

742742
try {
743-
const author = await this.getProviderAccountForCommit(this._session!, repo, ref, options);
743+
const author = await this.getProviderAccountForCommit(this._session!, repo, rev, options);
744744
this.resetRequestExceptionCount();
745745
return author;
746746
} catch (ex) {
@@ -751,7 +751,7 @@ export abstract class HostingIntegration<
751751
protected abstract getProviderAccountForCommit(
752752
session: ProviderAuthenticationSession,
753753
repo: T,
754-
ref: string,
754+
rev: string,
755755
options?: {
756756
avatarSize?: number;
757757
},
@@ -911,7 +911,7 @@ export abstract class HostingIntegration<
911911
@debug()
912912
async getPullRequestForCommit(
913913
repo: T,
914-
ref: string,
914+
rev: string,
915915
options?: { expiryOverride?: boolean | number },
916916
): Promise<PullRequest | undefined> {
917917
const scope = getLogScope();
@@ -920,13 +920,13 @@ export abstract class HostingIntegration<
920920
if (!connected) return undefined;
921921

922922
const pr = this.container.cache.getPullRequestForSha(
923-
ref,
923+
rev,
924924
repo,
925925
this,
926926
() => ({
927927
value: (async () => {
928928
try {
929-
const result = await this.getProviderPullRequestForCommit(this._session!, repo, ref);
929+
const result = await this.getProviderPullRequestForCommit(this._session!, repo, rev);
930930
this.resetRequestExceptionCount();
931931
return result;
932932
} catch (ex) {
@@ -942,7 +942,7 @@ export abstract class HostingIntegration<
942942
protected abstract getProviderPullRequestForCommit(
943943
session: ProviderAuthenticationSession,
944944
repo: T,
945-
ref: string,
945+
rev: string,
946946
): Promise<PullRequest | undefined>;
947947

948948
async getMyIssuesForRepos(

src/plus/integrations/providers/azureDevOps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class AzureDevOpsIntegration extends HostingIntegration<
220220
protected override async getProviderAccountForCommit(
221221
_session: AuthenticationSession,
222222
_repo: AzureRepositoryDescriptor,
223-
_ref: string,
223+
_rev: string,
224224
_options?: {
225225
avatarSize?: number;
226226
},
@@ -295,7 +295,7 @@ export class AzureDevOpsIntegration extends HostingIntegration<
295295
protected override async getProviderPullRequestForCommit(
296296
_session: AuthenticationSession,
297297
_repo: AzureRepositoryDescriptor,
298-
_ref: string,
298+
_rev: string,
299299
): Promise<PullRequest | undefined> {
300300
return Promise.resolve(undefined);
301301
}

src/plus/integrations/providers/bitbucket-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class BitbucketServerIntegration extends HostingIntegration<
6565
protected override async getProviderAccountForCommit(
6666
_session: AuthenticationSession,
6767
_repo: BitbucketRepositoryDescriptor,
68-
_ref: string,
68+
_rev: string,
6969
_options?: {
7070
avatarSize?: number;
7171
},
@@ -150,7 +150,7 @@ export class BitbucketServerIntegration extends HostingIntegration<
150150
protected override async getProviderPullRequestForCommit(
151151
_session: AuthenticationSession,
152152
_repo: BitbucketRepositoryDescriptor,
153-
_ref: string,
153+
_rev: string,
154154
): Promise<PullRequest | undefined> {
155155
return Promise.resolve(undefined);
156156
}

src/plus/integrations/providers/bitbucket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class BitbucketIntegration extends HostingIntegration<
5151
protected override async getProviderAccountForCommit(
5252
_session: AuthenticationSession,
5353
_repo: BitbucketRepositoryDescriptor,
54-
_ref: string,
54+
_rev: string,
5555
_options?: {
5656
avatarSize?: number;
5757
},
@@ -133,7 +133,7 @@ export class BitbucketIntegration extends HostingIntegration<
133133
protected override async getProviderPullRequestForCommit(
134134
_session: AuthenticationSession,
135135
_repo: BitbucketRepositoryDescriptor,
136-
_ref: string,
136+
_rev: string,
137137
): Promise<PullRequest | undefined> {
138138
return Promise.resolve(undefined);
139139
}

src/plus/integrations/providers/github.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
4747
protected override async getProviderAccountForCommit(
4848
{ accessToken }: AuthenticationSession,
4949
repo: GitHubRepositoryDescriptor,
50-
ref: string,
50+
rev: string,
5151
options?: {
5252
avatarSize?: number;
5353
},
5454
): Promise<Account | UnidentifiedAuthor | undefined> {
55-
return (await this.container.github)?.getAccountForCommit(this, accessToken, repo.owner, repo.name, ref, {
55+
return (await this.container.github)?.getAccountForCommit(this, accessToken, repo.owner, repo.name, rev, {
5656
...options,
5757
baseUrl: this.apiBaseUrl,
5858
});
@@ -156,9 +156,9 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
156156
protected override async getProviderPullRequestForCommit(
157157
{ accessToken }: AuthenticationSession,
158158
repo: GitHubRepositoryDescriptor,
159-
ref: string,
159+
rev: string,
160160
): Promise<PullRequest | undefined> {
161-
return (await this.container.github)?.getPullRequestForCommit(this, accessToken, repo.owner, repo.name, ref, {
161+
return (await this.container.github)?.getPullRequestForCommit(this, accessToken, repo.owner, repo.name, rev, {
162162
baseUrl: this.apiBaseUrl,
163163
});
164164
}

src/plus/integrations/providers/github/github.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export class GitHubApi implements Disposable {
313313
token: string,
314314
owner: string,
315315
repo: string,
316-
ref: string,
316+
rev: string,
317317
options?: {
318318
baseUrl?: string;
319319
avatarSize?: number;
@@ -346,11 +346,11 @@ export class GitHubApi implements Disposable {
346346
const query = `query getAccountForCommit(
347347
$owner: String!
348348
$repo: String!
349-
$ref: GitObjectID!
349+
$rev: GitObjectID!
350350
$avatarSize: Int
351351
) {
352352
repository(name: $repo, owner: $owner) {
353-
object(oid: $ref) {
353+
object(oid: $rev) {
354354
... on Commit {
355355
author {
356356
name
@@ -373,7 +373,7 @@ export class GitHubApi implements Disposable {
373373
...options,
374374
owner: owner,
375375
repo: repo,
376-
ref: ref,
376+
rev: rev,
377377
},
378378
scope,
379379
);
@@ -859,7 +859,7 @@ export class GitHubApi implements Disposable {
859859
token: string,
860860
owner: string,
861861
repo: string,
862-
ref: string,
862+
rev: string,
863863
options?: {
864864
baseUrl?: string;
865865
avatarSize?: number;
@@ -885,11 +885,11 @@ export class GitHubApi implements Disposable {
885885
const query = `query getPullRequestForCommit(
886886
$owner: String!
887887
$repo: String!
888-
$ref: GitObjectID!
888+
$rev: GitObjectID!
889889
$avatarSize: Int
890890
) {
891891
repository(name: $repo, owner: $owner) {
892-
object(oid: $ref) {
892+
object(oid: $rev) {
893893
... on Commit {
894894
associatedPullRequests(first: 2, orderBy: {field: UPDATED_AT, direction: DESC}) {
895895
nodes {
@@ -909,7 +909,7 @@ export class GitHubApi implements Disposable {
909909
...options,
910910
owner: owner,
911911
repo: repo,
912-
ref: ref,
912+
rev: rev,
913913
},
914914
scope,
915915
cancellation,

src/plus/integrations/providers/gitlab.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ abstract class GitLabIntegrationBase<
5353
protected override async getProviderAccountForCommit(
5454
{ accessToken }: AuthenticationSession,
5555
repo: GitLabRepositoryDescriptor,
56-
ref: string,
56+
rev: string,
5757
options?: {
5858
avatarSize?: number;
5959
},
6060
): Promise<Account | undefined> {
61-
return (await this.container.gitlab)?.getAccountForCommit(this, accessToken, repo.owner, repo.name, ref, {
61+
return (await this.container.gitlab)?.getAccountForCommit(this, accessToken, repo.owner, repo.name, rev, {
6262
...options,
6363
baseUrl: this.apiBaseUrl,
6464
});
@@ -167,9 +167,9 @@ abstract class GitLabIntegrationBase<
167167
protected override async getProviderPullRequestForCommit(
168168
{ accessToken }: AuthenticationSession,
169169
repo: GitLabRepositoryDescriptor,
170-
ref: string,
170+
rev: string,
171171
): Promise<PullRequest | undefined> {
172-
return (await this.container.gitlab)?.getPullRequestForCommit(this, accessToken, repo.owner, repo.name, ref, {
172+
return (await this.container.gitlab)?.getPullRequestForCommit(this, accessToken, repo.owner, repo.name, rev, {
173173
baseUrl: this.apiBaseUrl,
174174
});
175175
}

src/plus/integrations/providers/gitlab/gitlab.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class GitLabApi implements Disposable {
9797
token: string,
9898
owner: string,
9999
repo: string,
100-
ref: string,
100+
rev: string,
101101
options?: {
102102
baseUrl?: string;
103103
avatarSize?: number;
@@ -114,7 +114,7 @@ export class GitLabApi implements Disposable {
114114
provider,
115115
token,
116116
options?.baseUrl,
117-
`v4/projects/${projectId}/repository/commits/${ref}?stats=false`,
117+
`v4/projects/${projectId}/repository/commits/${rev}?stats=false`,
118118
{
119119
method: 'GET',
120120
// ...options,
@@ -533,7 +533,7 @@ export class GitLabApi implements Disposable {
533533
token: string,
534534
owner: string,
535535
repo: string,
536-
ref: string,
536+
rev: string,
537537
options?: {
538538
baseUrl?: string;
539539
avatarSize?: number;
@@ -550,7 +550,7 @@ export class GitLabApi implements Disposable {
550550
provider,
551551
token,
552552
options?.baseUrl,
553-
`v4/projects/${projectId}/repository/commits/${ref}/merge_requests`,
553+
`v4/projects/${projectId}/repository/commits/${rev}/merge_requests`,
554554
{
555555
method: 'GET',
556556
// ...options,

0 commit comments

Comments
 (0)