Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: version control #967

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add repository creation
Z3rio committed Jul 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fd9f9c58602da01bf3a5c42c67c28845a45ab687
47 changes: 47 additions & 0 deletions core/components/VersionControl/index.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,53 @@ export default class VersionControl {
await this.updateOctokitValue();
}

public async createGithubRepo(
repoName: string,
ownerName: string,
isOrganization: boolean
): Promise<[boolean, any?]> {
console.log({
repoName,
ownerName,
isOrganization
});
if (this.octokit) {
if (isOrganization === true) {
const resp = this.octokit.request("POST /orgs/{org}/repos", {
org: ownerName,
name: repoName,
description: "Server repository created by txAdmin",
private: true,
has_issues: true,
has_projects: true,
has_wiki: true,
is_template: false
});
console.log("resp", JSON.stringify(resp));

if (resp.status === 200) {
return [true, resp.data];
}
} else {
const resp = this.octokit.request("POST /user/repos", {
name: repoName,
description: "Server repository created by txAdmin",
private: true,
has_issues: true,
has_projects: true,
has_wiki: true,
is_template: false
});

if (resp.status === 200) {
return [true, resp.data];
}
}
}

return [false];
}

public async isAuthKeyValid(key: string) {
try {
const val = await new Octokit({
5 changes: 4 additions & 1 deletion core/extras/deployer.js
Original file line number Diff line number Diff line change
@@ -239,7 +239,10 @@ export class Deployer {
this.validGithubData = typeof globals.deployer.recipe.variables.githubAutoFork === 'boolean' && typeof globals.deployer.recipe.variables.githubAuthKey === 'string' && globals.deployer.recipe.variables.githubAuthKey.trim().length > 0 && typeof globals.deployer.recipe.variables.githubOwner === 'string' && globals.deployer.recipe.variables.githubOwner.trim().length > 0 && typeof globals.deployer.recipe.variables.githubParentRepo === 'string' && globals.deployer.recipe.variables.githubParentRepo.trim().length > 0;
if (this.validGithubData == true) {
const localUsername = await globals.versionControl.getUsername();
this.isOwnerOrganization = this.recipe.variables.githubOwner === localUsername;
this.isOwnerOrganization = this.recipe.variables.githubOwner !== localUsername;

const repoCreationResp = await globals.versionControl.createGithubRepo(this.recipe.variables.githubParentRepo, this.recipe.variables.githubOwner, this.isOwnerOrganization);
console.log('repoCreationResp', repoCreationResp);
}
this.runTasks();
}