Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 21 additions & 7 deletions client/src/components/pipelines/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ export default defineComponent({
gogs: false,
docker: true
},
repositoriesListLoaded: false, // flag to indicate if repositoriesList has been loaded
git: {
keys: {},
repository: {},
Expand Down Expand Up @@ -721,11 +722,12 @@ export default defineComponent({
},
mounted() {
this.getContextList();
this.listRepositories();
this.listRepositories().then(() => {
this.loadRepository();
this.loadPipeline();
});
this.loadDefaultregistry();
this.listBuildpacks();
this.loadRepository();
this.loadPipeline();
},
components: {
Breadcrumbs,
Expand All @@ -747,10 +749,18 @@ export default defineComponent({
}
});
},
listRepositories() {
axios.get('/api/repo/providers').then(response => {
this.repositoriesList = response.data
});
async listRepositories() {
const response = await axios.get('/api/repo/providers');
this.repositoriesList = response.data
this.repositoriesListLoaded = true;
// Set default repotab to first enabled provider (not github by default)
const providers = ['github', 'gitea', 'gitlab', 'gogs', 'bitbucket'];
for (const provider of providers) {
if (this.repositoriesList[provider as keyof typeof this.repositoriesList] === true) {
this.repotab = provider;
break;
}
}
},
listBuildpacks() {
axios.get('/api/config/runpacks').then(response => {
Expand Down Expand Up @@ -827,6 +837,10 @@ export default defineComponent({
},

loadRepository() {
// Only load repositories if the selected provider is enabled
if (!this.repositoriesList[this.repotab as keyof typeof this.repositoriesList]) {
return;
}
axios.get(`/api/repo/${this.repotab}/repositories`)
.then(response => {
this.gitrepoItems = response.data;
Expand Down
34 changes: 33 additions & 1 deletion server/src/repo/git/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import { RequestError } from '@octokit/types';

export class GithubApi extends Repo {
private octokit: any;
private token: string;

constructor(baseUrl: string, token: string) {
super('github');

if (baseUrl === '') {
this.token = token;

if (!baseUrl || baseUrl === '') {
baseUrl = 'https://api.github.com';
}

Expand All @@ -31,6 +34,10 @@ export class GithubApi extends Repo {
});
}

private isConfigured(): boolean {
return !!this.token && this.token !== '';
}

protected async getRepository(gitrepo: string): Promise<IRepository> {
let ret: IRepository = {
status: 500,
Expand All @@ -43,6 +50,11 @@ export class GithubApi extends Repo {
},
};

if (!this.isConfigured()) {
this.logger.debug('GitHub API is not configured, skipping getRepository');
return ret;
}

const parsed = gitUrlParse(gitrepo);
const repo = parsed.name;
const owner = parsed.owner;
Expand Down Expand Up @@ -92,6 +104,10 @@ export class GithubApi extends Repo {
}

public async getRepositories() {
if (!this.isConfigured()) {
this.logger.debug('GitHub API is not configured, skipping getRepositories');
return [];
}
const res = await this.octokit.request('GET /user/repos', {});
return res.data;
}
Expand Down Expand Up @@ -308,6 +324,10 @@ export class GithubApi extends Repo {

public async listRepos(): Promise<string[]> {
const ret: string[] = [];
if (!this.isConfigured()) {
this.logger.debug('GitHub API is not configured, skipping listRepos');
return ret;
}
try {
const repos = await this.octokit.request('GET /user/repos', {
visibility: 'all',
Expand All @@ -325,6 +345,10 @@ export class GithubApi extends Repo {

public async getBranches(gitrepo: string): Promise<string[]> {
const ret: string[] = [];
if (!this.isConfigured()) {
this.logger.debug('GitHub API is not configured, skipping getBranches');
return ret;
}

const { repo, owner } = this.parseRepo(gitrepo);

Expand All @@ -348,6 +372,10 @@ export class GithubApi extends Repo {

public async getReferences(gitrepo: string): Promise<string[]> {
const ret: string[] = [];
if (!this.isConfigured()) {
this.logger.debug('GitHub API is not configured, skipping getReferences');
return ret;
}

const { repo, owner } = this.parseRepo(gitrepo);

Expand Down Expand Up @@ -401,6 +429,10 @@ export class GithubApi extends Repo {

public async getPullrequests(gitrepo: string): Promise<IPullrequest[]> {
const ret: IPullrequest[] = [];
if (!this.isConfigured()) {
this.logger.debug('GitHub API is not configured, skipping getPullrequests');
return ret;
}

const { repo, owner } = this.parseRepo(gitrepo);

Expand Down