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

Gitea support #8131

Draft
wants to merge 23 commits into
base: main
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
replace gitlab names with gitea
  • Loading branch information
anbraten committed Feb 10, 2022
commit e5057263eec713260df707a8c6cb202a64f76604
8 changes: 2 additions & 6 deletions components/server/ee/src/gitea/gitea-app-support.ts
Original file line number Diff line number Diff line change
@@ -28,12 +28,8 @@ export class GiteaAppSupport {
if (!identity) {
return result;
}
const usersGitLabAccount = identity.authName;
const usersAccount = identity.authName;

// cf. https://docs.gitlab.com/ee/api/projects.html#list-all-projects
// we are listing only those projects with access level of maintainers.
// also cf. https://docs.gitlab.com/ee/api/members.html#valid-access-levels
//
// TODO: check if valid
const projectsWithAccess = await api.user.userCurrentListRepos({ limit: 100 });
for (const project of projectsWithAccess.data) {
@@ -43,7 +39,7 @@ export class GiteaAppSupport {
const accountAvatarUrl = project.owner?.avatar_url as string;
const account = project.owner?.login as string;

(account === usersGitLabAccount ? ownersRepos : result).push({
(account === usersAccount ? ownersRepos : result).push({
name: project.name as string,
path,
account,
63 changes: 9 additions & 54 deletions components/server/ee/src/prebuilds/gitea-app.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import { TraceContext } from '@gitpod/gitpod-protocol/lib/util/tracing';
import { TokenService } from '../../../src/user/token-service';
import { HostContextProvider } from '../../../src/auth/host-context-provider';
// import { GiteaService } from './gitea-service';
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';

@injectable()
export class GiteaApp {
@@ -30,38 +29,15 @@ export class GiteaApp {

@postConstruct()
protected init() {
this._router.post('/', async (req, res) => {
const event = req.header('X-Gitlab-Event');
if (event === 'Push Hook') {
const context = req.body as GitLabPushHook;
const span = TraceContext.startSpan("GitLapApp.handleEvent", {});
span.setTag("request", context);
log.debug("GitLab push hook received", { event, context });
let user: User | undefined;
try {
user = await this.findUser({ span }, context, req);
} catch (error) {
log.error("Cannot find user.", error, { req })
}
if (!user) {
res.statusCode = 503;
res.send();
return;
}
await this.handlePushHook({ span }, context, user);
} else {
log.debug("Unknown GitLab event received", { event });
}
res.send('OK');
});
// TODO
}

protected async findUser(ctx: TraceContext, context: GitLabPushHook, req: express.Request): Promise<User> {
protected async findUser(ctx: TraceContext, context: GiteaPushHook, req: express.Request): Promise<User> {
// TODO
return {} as User;
}

protected async handlePushHook(ctx: TraceContext, body: GitLabPushHook, user: User): Promise<StartPrebuildResult | undefined> {
protected async handlePushHook(ctx: TraceContext, body: GiteaPushHook, user: User): Promise<StartPrebuildResult | undefined> {
// TODO
return undefined;
}
@@ -82,10 +58,9 @@ export class GiteaApp {
return {} as { user: User, project?: Project };
}

protected createContextUrl(body: GitLabPushHook) {
const repoUrl = body.repository.git_http_url;
const contextURL = `${repoUrl.substr(0, repoUrl.length - 4)}/-/tree${body.ref.substr('refs/head/'.length)}`;
return contextURL;
protected createContextUrl(body: GiteaPushHook) {
// TODO
return {};
}

get router(): express.Router {
@@ -102,30 +77,10 @@ export class GiteaApp {
}
}

interface GitLabPushHook {
object_kind: 'push';
before: string;
after: string; // commit
ref: string; // e.g. "refs/heads/master"
user_avatar: string;
user_name: string;
project: GitLabProject;
repository: GitLabRepository;
interface GiteaPushHook {
}

interface GitLabRepository {
name: string,
git_http_url: string; // e.g. http://example.com/mike/diaspora.git
visibility_level: number,
interface GiteaRepository {
}

interface GitLabProject {
id: number,
namespace: string,
name: string,
path_with_namespace: string, // e.g. "mike/diaspora"
git_http_url: string; // e.g. http://example.com/mike/diaspora.git
web_url: string; // e.g. http://example.com/mike/diaspora
visibility_level: number,
avatar_url: string | null,
}
interface GiteaProject {}