7
7
import { NavigatorContext , Repository , User , WorkspaceContext } from "@gitpod/gitpod-protocol" ;
8
8
import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
9
9
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
10
- import { Schema } from "bitbucket" ;
10
+ import { Schema } from "@atlassian/ bitbucket-server " ;
11
11
import { inject , injectable } from "inversify" ;
12
12
import { BitbucketTokenHelper } from "../bitbucket/bitbucket-token-handler" ;
13
13
import { NotFoundError } from "../errors" ;
@@ -47,34 +47,36 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
47
47
return undefined ;
48
48
}
49
49
50
- protected async isValidCommitHash ( user : User , owner : string , repoName : string , potentialCommitHash : string ) {
51
- if ( potentialCommitHash . length !== 40 ) {
52
- return false ;
53
- }
50
+ // protected async isValidCommitHash(user: User, owner: string, repoName: string, potentialCommitHash: string) {
51
+ // if (potentialCommitHash.length !== 40) {
52
+ // return false;
53
+ // }
54
+ // try {
55
+ // const api = await this.api(user);
56
+ // const result = (await api.repositories.getCommit({ workspace: owner, repo_slug: repoName, commit: potentialCommitHash }));
57
+ // return result.data.hash === potentialCommitHash;
58
+ // } catch {
59
+ // return false;
60
+ // }
61
+ // }
62
+
63
+ // protected async isTag(user: User, owner: string, repoName: string, potentialTag: string) {
64
+ // try {
65
+ // const api = await this.api(user);
66
+ // const result = (await api.repositories.getTag({ workspace: owner, repo_slug: repoName, name: potentialTag }));
67
+ // return result.data.name === potentialTag;
68
+ // } catch {
69
+ // return false;
70
+ // }
71
+ // }
72
+
73
+ protected async handleNavigatorContext ( ctx : TraceContext , user : User , host : string , owner : string , repoName : string , more : Partial < NavigatorContext > = { } ) : Promise < NavigatorContext > {
74
+ const span = TraceContext . startSpan ( "BitbucketServerContextParser.handleNavigatorContext" , ctx ) ;
54
75
try {
55
76
const api = await this . api ( user ) ;
56
- const result = ( await api . repositories . getCommit ( { workspace : owner , repo_slug : repoName , commit : potentialCommitHash } ) ) ;
57
- return result . data . hash === potentialCommitHash ;
58
- } catch {
59
- return false ;
60
- }
61
- }
62
77
63
- protected async isTag ( user : User , owner : string , repoName : string , potentialTag : string ) {
64
- try {
65
- const api = await this . api ( user ) ;
66
- const result = ( await api . repositories . getTag ( { workspace : owner , repo_slug : repoName , name : potentialTag } ) ) ;
67
- return result . data . name === potentialTag ;
68
- } catch {
69
- return false ;
70
- }
71
- }
78
+ const repo = ( await api . repos . getRepository ( { projectKey : owner , repositorySlug : repoName } ) ) . data ;
72
79
73
- protected async handleNavigatorContext ( ctx : TraceContext , user : User , host : string , owner : string , repoName : string , more : Partial < NavigatorContext > = { } , givenRepo ?: Schema . Repository ) : Promise < NavigatorContext > {
74
- const span = TraceContext . startSpan ( "BitbucketServerContextParser.handleNavigatorContext" , ctx ) ;
75
- try {
76
- const api = await this . api ( user ) ;
77
- const repo = givenRepo || ( await api . repositories . get ( { workspace : owner , repo_slug : repoName } ) ) . data ;
78
80
const repository = await this . toRepository ( user , host , repo ) ;
79
81
span . log ( { "request.finished" : "" } ) ;
80
82
@@ -87,24 +89,24 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
87
89
}
88
90
more . refType = more . refType || "branch" ;
89
91
90
- if ( ! more . revision ) {
91
- const commits = ( await api . repositories . listCommitsAt ( { workspace : owner , repo_slug : repoName , revision : more . ref ! , pagelen : 1 } ) ) . data ;
92
- more . revision = commits . values && commits . values . length > 0 ? commits . values [ 0 ] . hash : "" ;
93
- if ( ( ! commits . values || commits . values . length === 0 ) && more . ref === repository . defaultBranch ) {
94
- // empty repo
95
- more . ref = undefined ;
96
- more . revision = "" ;
97
- more . refType = undefined ;
98
- }
99
- }
100
-
101
- if ( ! more . path ) {
102
- more . isFile = false ;
103
- more . path = "" ;
104
- } else if ( more . isFile === undefined ) {
105
- const fileMeta = ( await api . repositories . readSrc ( { workspace : owner , repo_slug : repoName , format : "meta" , commit : more . revision ! , path : more . path ! , pagelen : 1 } ) ) . data ;
106
- more . isFile = ( fileMeta as any ) . type === "commit_file" ;
107
- }
92
+ // if (!more.revision) {
93
+ // const commits = (await api.repositories.listCommitsAt({ workspace: owner, repo_slug: repoName, revision: more.ref!, pagelen: 1 })).data;
94
+ // more.revision = commits.values && commits.values.length > 0 ? commits.values[0].hash : "";
95
+ // if ((!commits.values || commits.values.length === 0) && more.ref === repository.defaultBranch) {
96
+ // // empty repo
97
+ // more.ref = undefined;
98
+ // more.revision = "";
99
+ // more.refType = undefined;
100
+ // }
101
+ // }
102
+
103
+ // if (!more.path) {
104
+ // more.isFile = false;
105
+ // more.path = "";
106
+ // } else if (more.isFile === undefined) {
107
+ // const fileMeta = (await api.repositories.readSrc({ workspace: owner, repo_slug: repoName, format: "meta", commit: more.revision!, path: more.path!, pagelen: 1 })).data;
108
+ // more.isFile = (fileMeta as any).type === "commit_file";
109
+ // }
108
110
109
111
return {
110
112
...more ,
@@ -125,27 +127,26 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
125
127
if ( ! repo ) {
126
128
throw new Error ( 'Unknown repository.' ) ;
127
129
}
128
- // full_name: string
129
- // The concatenation of the repository owner's username and the slugified name, e.g. "evzijst/interruptingcow". This is the same string used in Bitbucket URLs.
130
- const fullName = repo . full_name ! . split ( "/" ) ;
131
- const owner = fullName [ 0 ] ;
132
- const name = fullName [ 1 ] ;
130
+
131
+ const owner = repo . project . key ;
132
+ const name = repo . name ;
133
+ const cloneUrl = repo . links . clone . find ( u => u . name === "http" ) ?. href ! ;
133
134
134
135
const result : Repository = {
135
- cloneUrl : `https:// ${ host } / ${ repo . full_name } .git` ,
136
+ cloneUrl,
136
137
host,
137
138
name,
138
139
owner,
139
- private : ! ! repo . isPrivate ,
140
- defaultBranch : repo . mainbranch ? repo . mainbranch . name : DEFAULT_BRANCH ,
141
- }
142
- if ( ! ! repo . parent && ! ! repo . parent . full_name ) {
143
- const api = await this . api ( user ) ;
144
- const parentRepo = ( await api . repositories . get ( { workspace : repo . parent ! . full_name ! . split ( "/" ) [ 0 ] , repo_slug : repo . parent ! . full_name ! . split ( "/" ) [ 1 ] } ) ) . data ;
145
- result . fork = {
146
- parent : await this . toRepository ( user , host , parentRepo )
147
- } ;
140
+ private : ! repo . public ,
141
+ defaultBranch : DEFAULT_BRANCH ,
148
142
}
143
+ // if (!!repo.parent && !!repo.parent.full_name) {
144
+ // const api = await this.api(user);
145
+ // const parentRepo = (await api.repositories.get({ workspace: repo.parent!.full_name!.split("/")[0], repo_slug: repo.parent!.full_name!.split("/")[1] })).data;
146
+ // result.fork = {
147
+ // parent: await this.toRepository(user, host, parentRepo)
148
+ // };
149
+ // }
149
150
150
151
return result ;
151
152
}
0 commit comments