Permalink
Browse files

feat(): gogs integration

  • Loading branch information...
Izak88 committed Aug 26, 2017
1 parent 111d209 commit 09b79498a7d93c1690f1910a8e78a05ce2be25b7

This file was deleted.

Oops, something went wrong.
@@ -104,9 +104,9 @@ export function getRepositoryDetails(repository, sha = null, pr = null): Promise
if (repository.private && repository.gitlab_id && repository.access_token) {
cloneUrl =
cloneUrl.replace('https://', `https://gitlab-ci-token:${repository.access_token}@`);
}

if (repository.bitbucket_id && repository.private && repository.access_token) {
} else if (repository.private && repository.gogs_id && repository.access_token) {
cloneUrl = cloneUrl.replace('https://', `https://${repository.access_token}@`);
} else if (repository.bitbucket_id && repository.private && repository.access_token) {
return getBitBucketAccessToken(repository.access_token)
.then(response => {
let access_token = JSON.parse(response).access_token;
@@ -27,6 +27,7 @@ export function create(): Promise<null> {
t.integer('github_id');
t.string('bitbucket_id');
t.integer('gitlab_id');
t.integer('gogs_id');
t.string('clone_url');
t.string('html_url');
t.string('default_branch');
@@ -180,6 +180,8 @@ export function updateRepository(data: any): Promise<boolean> {
repository = new Repository().where({ bitbucket_id: data.bitbucket_id });
} else if (data.gitlab_id) {
repository = new Repository().where({ gitlab_id: data.gitlab_id });
} else if (data.gogs_id) {
repository = new Repository().where({ gogs_id: data.gogs_id });
} else {
reject('Repository Id missing');
}
@@ -265,14 +267,49 @@ export function pingGitLabRepository(data: any): Promise<any> {
const saveData = generateGitLabRepositoryData(data);
new Repository().where({ gitlab_id: saveData.gitlab_id }).fetch()
.then(repo => {
if (!repo) {
new Repository().save(saveData, { method: 'insert' })
.then(result => {
if (!result) {
reject(result);
} else {
let repository = result.toJSON();

return addRepositoryPermissionToEveryone(repository.id)
.then(() => resolve(repository))
.catch(err => reject(err));
}
})
.catch(err => reject(err));
} else {
repo.save(saveData, { method: 'update', require: false })
.then(result => {
if (!result) {
reject(result);
} else {
resolve(result.toJSON());
}
})
.catch(err => reject(err));
}
});
});
}

export function pingGogsRepository(data: any): Promise<any> {
return new Promise((resolve, reject) => {
const saveData = generateGogsRepositoryData(data);
new Repository().where({ gogs_id: saveData.gogs_id }).fetch()
.then(repo => {
if (!repo) {
new Repository().save(saveData, { method: 'insert' })
.then(result => {
if (!result) {
reject(result);
} else {
let repository = result.toJSON();
return addRepositoryPermissionToEveryone(result.id)

return addRepositoryPermissionToEveryone(repository.id)
.then(() => resolve(repository))
.catch(err => reject(err));
}
@@ -326,6 +363,32 @@ export function createGitHubPullRequest(data: any): Promise<any> {
});
}

export function createGogsPullRequest(data: any): Promise<any> {
return new Promise((resolve, reject) => {
let repoId = data.repository.id;
new Repository().where({ gogs_id: repoId }).fetch()
.then(repo => {
if (!repo) {
const repoData = generateGogsRepositoryData(data);
return addRepository(repoData);
} else {
return Promise.resolve(repo.toJSON());
}
})
.then(repo => {
const buildData = {
pr: data.number,
data: data,
start_time: new Date(),
repositories_id: repo.id
};

resolve(buildData);
})
.catch(err => reject(err));
});
}

export function synchronizeGitHubPullRequest(data: any): Promise<any> {
let repoId;
return new Promise((resolve, reject) => {
@@ -392,6 +455,38 @@ export function synchronizeBitbucketPullRequest(data: any): Promise<any> {
});
}

export function synchronizeGogsPullRequest(data: any): Promise<any> {
return new Promise((resolve, reject) => {
let repoId = data.repository.id;
new Repository().where({ gogs_id: repoId }).fetch()
.then(repository => {
if (!repository) {
const repoData = generateGogsRepositoryData(data);
return addRepository(repoData).then(repo => {
repoId = repo.id;
});
} else {
const repoJson = repository.toJSON();
repoId = repoJson.id;
const repoData = generateGogsRepositoryData(data);

return updateRepository(repoData);
}
})
.then(() => {
const buildData = {
pr: data.pull_request ? data.pull_request.id : null,
data: data,
start_time: new Date(),
repositories_id: repoId
};

resolve(buildData);
})
.catch(err => reject(err));
});
}

export function synchronizeGitLabPullRequest(data: any): Promise<any> {
let repoId;
return new Promise((resolve, reject) => {
@@ -480,3 +575,21 @@ function generateGitLabRepositoryData(data: any): any {
data: data
};
}

function generateGogsRepositoryData(data: any): any {
return {
gogs_id: data.repository.id,
clone_url: data.repository.clone_url,
html_url: data.repository.html_url,
default_branch: data.repository.default_branch,
name: data.repository.name,
full_name: data.repository.full_name,
description: data.repository.description,
private: data.repository.private,
fork: data.repository.fork,
user_login: data.repository.owner.login,
user_id: data.repository.owner.id,
user_avatar_url: data.repository.owner.avatar_url,
data: data
};
}
@@ -102,7 +102,6 @@ export function startBuild(data: any): Promise<any> {
return getRepositoryDetails(repository, sha, pr)
.then(details => {
repoDetails = details;

if (pr) {
repoDetails.config.git.pr = data.pr;
} else if (!sha) {
Oops, something went wrong.

0 comments on commit 09b7949

Please sign in to comment.