@@ -50,7 +50,7 @@ export class BitbucketPublisher implements PublisherBase {
50
50
values : RequiredTemplateValues & Record < string , JsonValue > ,
51
51
) : Promise < PublisherResult > {
52
52
const [ project , name ] = values . storePath . split ( '/' ) ;
53
- if ( this . host === 'bitbucket.org' ) {
53
+ if ( this . host === 'https:// bitbucket.org' ) {
54
54
return this . createBitbucketCloudRepository ( project , name ) ;
55
55
}
56
56
return this . createBitbucketServerRepository ( project , name ) ;
@@ -60,9 +60,39 @@ export class BitbucketPublisher implements PublisherBase {
60
60
project : string ,
61
61
name : string ,
62
62
) : Promise < PublisherResult > {
63
- throw new Error (
64
- `Failed to create ${ project } /${ name } on bitbucket.org which is currently not supported` ,
65
- ) ;
63
+ let response : Response ;
64
+ const buffer = Buffer . from ( `${ this . username } :${ this . token } ` , 'utf8' ) ;
65
+
66
+ const options : RequestInit = {
67
+ method : 'POST' ,
68
+ body : JSON . stringify ( { } ) ,
69
+ headers : {
70
+ Authorization : `Basic ${ buffer . toString ( 'base64' ) } ` ,
71
+ 'Content-Type' : 'application/json' ,
72
+ } ,
73
+ } ;
74
+ try {
75
+ response = await fetch (
76
+ `https://api.bitbucket.org/2.0/repositories/${ project } /${ name } ` ,
77
+ options ,
78
+ ) ;
79
+ } catch ( e ) {
80
+ throw new Error ( `Unable to create repository, ${ e } ` ) ;
81
+ }
82
+ if ( response . status === 200 ) {
83
+ const r = await response . json ( ) ;
84
+ let remoteUrl = '' ;
85
+ for ( const link of r . links . clone ) {
86
+ if ( link . name === 'https' ) {
87
+ remoteUrl = link . href ;
88
+ }
89
+ }
90
+
91
+ // TODO use the urlReader to get the defautl branch
92
+ const catalogInfoUrl = `${ r . links . html . href } /src/master/catalog-info.yaml` ;
93
+ return { remoteUrl, catalogInfoUrl } ;
94
+ }
95
+ throw new Error ( `Not a valid response code ${ await response . text ( ) } ` ) ;
66
96
}
67
97
68
98
private async createBitbucketServerRepository (
0 commit comments