Skip to content

Commit 9993e4a

Browse files
author
azliabdullah
committed
fixed bug where recreating repo for an organisation, the repo recreated in authenticated user account instead (fix issue piceaTech#153)
1 parent f3a715e commit 9993e4a

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ Point this to the api. The default is `api.github.com`.
7474

7575
Under which organisation or user will the new project be hosted
7676

77+
#### github.ownerIsOrg
78+
79+
A boolean indicator (default is *false*) to specify that the owner of this repo is an Organisation.
80+
7781
#### github.token
7882

7983
Go to [Settings / Developer settings / Personal access tokens](https://github.com/settings/tokens). Generate a new token with `repo` scope and copy that into the `settings.ts`
@@ -90,6 +94,8 @@ What is the name of the new repo
9094

9195
If true (default is false), we will try to delete the destination github repository if present, and (re)create it. The github token must be granted `delete_repo` scope. The newly created repository will be made private by default.
9296

97+
If you've set `github.recreateRepo` to true and the repo belongs to an Organisation, the `github.ownerIsOrg` flag **must** be set as true.
98+
9399
This is useful when debugging this tool or a specific migration. You will always be prompted for confirmation.
94100

95101
### s3 (optional)

sample_settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
// baseUrl: 'https://github.mycompany.com:123/etc',
1212
// apiUrl: 'https//api.github.mycompany.com',
1313
owner: '{{repository owner (user or organization)}}',
14+
ownerIsOrg: false,
1415
token: '{{token}}',
1516
token_owner: '{{token_owner}}',
1617
repo: '{{repo}}',

src/githubHelper.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export class GithubHelper {
6060
githubApi: GitHubApi;
6161
githubUrl: string;
6262
githubOwner: string;
63+
githubOwnerIsOrg: boolean;
6364
githubToken: string;
65+
githubTokenOwner: string;
6466
githubRepo: string;
6567
githubTimeout?: number;
6668
gitlabHelper: GitlabHelper;
@@ -80,7 +82,9 @@ export class GithubHelper {
8082
? githubSettings.baseUrl
8183
: gitHubLocation;
8284
this.githubOwner = githubSettings.owner;
85+
this.githubOwnerIsOrg = githubSettings.ownerIsOrg ?? false;
8386
this.githubToken = githubSettings.token;
87+
this.githubTokenOwner = githubSettings.token_owner;
8488
this.githubRepo = githubSettings.repo;
8589
this.githubTimeout = githubSettings.timeout;
8690
this.gitlabHelper = gitlabHelper;
@@ -1398,11 +1402,20 @@ export class GithubHelper {
13981402
else console.error(`\n\tSomething went wrong: ${err}.`);
13991403
}
14001404
try {
1401-
console.log(`Creating repo ${params.owner}/${params.repo}...`);
1402-
await this.githubApi.repos.createForAuthenticatedUser({
1403-
name: this.githubRepo,
1404-
private: true,
1405-
});
1405+
if (this.githubOwnerIsOrg) {
1406+
console.log(`Creating repo in organisation ${this.githubOwner}/${this.githubRepo}...`);
1407+
await this.githubApi.repos.createInOrg({
1408+
org: this.githubOwner,
1409+
name: this.githubRepo,
1410+
private: true,
1411+
});
1412+
} else {
1413+
console.log(`Creating repo ${this.githubTokenOwner}/${this.githubRepo}...`);
1414+
await this.githubApi.repos.createForAuthenticatedUser({
1415+
name: this.githubRepo,
1416+
private: true,
1417+
});
1418+
}
14061419
console.log('\t...done.');
14071420
} catch (err) {
14081421
console.error(`\n\tSomething went wrong: ${err}.`);

src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface GithubSettings {
3838
baseUrl?: string;
3939
apiUrl?: string;
4040
owner: string;
41+
ownerIsOrg?: boolean;
4142
token: string;
4243
token_owner: string;
4344
repo: string;

0 commit comments

Comments
 (0)