Skip to content

Commit 1e3fc0a

Browse files
committed
feat(gogs-gitlab): gitlab and gogs integrated back
1 parent a4ece90 commit 1e3fc0a

File tree

13 files changed

+354
-285
lines changed

13 files changed

+354
-285
lines changed

e2e/100_gitlab.e2e.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ describe('Gitlab repositories', () => {
2525
.then(() => browser.get('/repositories'))
2626
.then((): any => isLoaded())
2727
.then((): any => browser.wait(() => element(by.css('.bold')).isPresent()))
28-
.then(() => expect(element.all(by.css('.bold')).last().getText()).to.include('test'))
28+
.then(() => {
29+
expect(element.all(by.css('.bold')).last().getText()).to.eventually.include('d3-bundle');
30+
})
2931
.then(() => browser.get('/'))
32+
.then(() => delay(3000))
3033
.then((): any => browser.wait(() => {
31-
return element(by.css('.list-item:nth-child(1) .stop-build')).isPresent();
34+
return element.all(by.css('.stop-build')).first().isPresent();
3235
}))
3336
.then((): any => browser.wait(() => {
34-
return element(by.css('.list-item:nth-child(1) .stop-build')).isEnabled();
37+
return element.all(by.css('.stop-build')).first().isDisplayed();
3538
}))
3639
.then(() => delay(2000))
37-
.then((): any => element.all(by.css('.list-item:nth-child(1) .stop-build')).click())
40+
.then((): any => element.all(by.css('.stop-build')).first().click())
3841
.then((): any => browser.wait(() => {
3942
return element.all(by.css('.is-running')).count().then(count => count === 0);
4043
}));

e2e/110_gogs.e2e.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ describe('Gogs repositories', () => {
2525
.then(() => browser.get('/repositories'))
2626
.then((): any => isLoaded())
2727
.then((): any => browser.wait(() => element(by.css('.bold')).isPresent()))
28-
.then(() => expect(element.all(by.css('.bold')).last().getText()).to.include('test'))
28+
.then(() => {
29+
expect(element.all(by.css('.bold')).last().getText()).to.eventually.include('d3-bundle');
30+
})
2931
.then(() => browser.get('/'))
32+
.then(() => delay(3000))
3033
.then((): any => browser.wait(() => {
31-
return element(by.css('.list-item:nth-child(1) .stop-build')).isPresent();
34+
return element.all(by.css('.stop-build')).first().isPresent();
3235
}))
3336
.then((): any => browser.wait(() => {
34-
return element(by.css('.list-item:nth-child(1) .stop-build')).isEnabled();
37+
return element.all(by.css('.stop-build')).first().isDisplayed();
3538
}))
3639
.then(() => delay(2000))
37-
.then((): any => element.all(by.css('.list-item:nth-child(1) .stop-build')).click())
40+
.then((): any => element.all(by.css('.stop-build')).first().click())
3841
.then((): any => browser.wait(() => {
3942
return element.all(by.css('.is-running')).count().then(count => count === 0);
4043
}));

e2e/120_team.e2e.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ describe('Teams', () => {
3939

4040
it('should redirect to team, user and then grant, revoke repository permission', () => {
4141
return browser.get('/team')
42-
.then((): any => browser.wait(() => element(by.css('.edit-user-button')).isPresent()))
42+
.then((): any => {
43+
return browser.wait(() => element.all(by.css('.edit-user-button')).last().isPresent());
44+
})
4345
.then((): any => element.all(by.css('.edit-user-button')).last().click())
4446
.then((): any => waitForUrlToChangeTo('http://localhost:6500/user/2'))
4547
.then((): any => browser.wait(() => element(by.css(`[name="tab-permissions"]`)).isPresent()))
4648
.then((): any => browser.wait(() => element(by.css(`[name="tab-permissions"]`)).isEnabled()))
4749
.then((): any => element(by.css('[name="tab-permissions"]')).click())
4850
.then((): any => browser.wait(() => {
49-
return element.all(by.css('.border-green')).count().then(count => count === 2);
51+
return element.all(by.css('.border-green')).count().then(count => count === 5);
5052
}))
5153
.then((): any => browser.wait(() => {
5254
return element.all(by.css('.border-red')).count().then(count => count === 0);
@@ -61,7 +63,7 @@ describe('Teams', () => {
6163
.then(ele => browser.executeScript('arguments[0].scrollIntoView();', ele.getWebElement()))
6264
.then((): any => element.all(by.css('[name="btn-removePermission"]')).first().click())
6365
.then((): any => browser.wait(() => {
64-
return element.all(by.css('.border-green')).count().then(count => count === 1);
66+
return element.all(by.css('.border-green')).count().then(count => count === 4);
6567
}))
6668
.then((): any => browser.wait(() => {
6769
return element.all(by.css('.border-red')).count()
@@ -77,7 +79,7 @@ describe('Teams', () => {
7779
.then(ele => browser.executeScript('arguments[0].scrollIntoView();', ele.getWebElement()))
7880
.then((): any => element.all(by.css('[name="btn-addPermission"]')).first().click())
7981
.then((): any => browser.wait(() => {
80-
return element.all(by.css('.border-green')).count().then(count => count === 2);
82+
return element.all(by.css('.border-green')).count().then(count => count === 5);
8183
}))
8284
.then((): any => browser.wait(() => {
8385
return element.all(by.css('.border-red')).count().then(count => count === 0);
@@ -110,7 +112,7 @@ describe('Teams', () => {
110112
.then((): any => element.all(by.css('.list-item')).first().click())
111113
.then(() => isLoaded())
112114
.then(() => delay(1000))
113-
.then(() => waitForUrlToChangeTo('http://localhost:6500/build/5'))
115+
.then(() => waitForUrlToChangeTo('http://localhost:6500/build/11'))
114116
.then((): any => element.all(by.css('[name="restart-build"]')).count())
115117
.then(cnt => expect(cnt).to.equals(0));
116118
});
@@ -125,7 +127,7 @@ describe('Teams', () => {
125127
.then((): any => element.all(by.css('.list-item-slim')).first().click())
126128
.then(() => isLoaded())
127129
.then(() => delay(1000))
128-
.then(() => waitForUrlToChangeTo('http://localhost:6500/job/5'))
130+
.then(() => waitForUrlToChangeTo('http://localhost:6500/job/11'))
129131
.then((): any => element.all(by.css('[name="restart-build"]')).count())
130132
.then(cnt => expect(cnt).to.equals(0));
131133
});

src/api/db/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ export function getDepracatedBuilds(build: any): Promise<any> {
307307
return build.data.before === b.data.before;
308308
} else if (build.data.before_sha) {
309309
return build.data.before_sha === b.data.before_sha;
310-
} else if (build.data.object_attributes && build.data.object_attirbutes.before_sha) {
311-
return build.data.object_attirbutes.before_sha
312-
=== b.data.object_attirbutes.before_sha;
310+
} else if (build.data.object_attributes && build.data.object_attributes.before_sha) {
311+
return build.data.object_attributes.before_sha
312+
=== b.data.object_attributes.before_sha;
313313
}
314314

315315
return false;

src/api/db/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ function generateBitbucketRepositoryData(data: any): any {
605605
}
606606

607607
function generateGitLabRepositoryData(data: any): any {
608-
const url = new URL(data.repository.clone_url);
608+
const url = new URL(data.repository.git_http_url || data.project.git_http_url);
609609
const apiUrl = url.protocol + '//' + url.host;
610610

611611
return {

src/app/components/app-build-details/app-build-details.component.ts

Lines changed: 100 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -267,97 +267,114 @@ export class AppBuildDetailsComponent implements OnInit, OnDestroy {
267267
data.commits && data.commits[data.commits.length - 1] && data.commits[data.commits.length - 1].timestamp ||
268268
null;
269269

270-
if (this.build.data.commit) {
271-
this.commitMessage = this.build.data.commit.message;
272-
} else if (this.build.data.commits) {
273-
const len = this.build.data.commits.length - 1;
274-
this.commitMessage = this.build.data.commits[len].message;
275-
} else if (this.build.data.pull_request && this.build.data.pull_request.title) {
276-
this.commitMessage = this.build.data.pull_request.title;
277-
} else if (this.build.data.head_commit) {
278-
this.commitMessage = this.build.data.head_commit.message;
279-
}
270+
if (this.build.repository.repository_provider === 'github') {
271+
if (this.build.data.commit) {
272+
this.commitMessage = this.build.data.commit.message;
273+
} else if (this.build.data.commits) {
274+
const len = this.build.data.commits.length - 1;
275+
this.commitMessage = this.build.data.commits[len].message;
276+
} else if (this.build.data.pull_request && this.build.data.pull_request.title) {
277+
this.commitMessage = this.build.data.pull_request.title;
278+
} else if (this.build.data.head_commit) {
279+
this.commitMessage = this.build.data.head_commit.message;
280+
}
281+
282+
if (this.build.data.sha) {
283+
const data = this.build.data;
284+
this.committerAvatar = data.committer.avatar_url;
285+
this.nameCommitter = data.commit.committer.name;
286+
this.authorAvatar = data.author.avatar_url;
287+
this.nameAuthor = data.commit.author.name;
288+
} else if (this.build.data.head_commit) {
289+
const commit = this.build.data.head_commit;
290+
this.committerAvatar = this.build.data.sender.avatar_url;
291+
this.nameCommitter = this.build.data.head_commit.author.name;
292+
293+
if (commit.author.username !== commit.committer.username) {
294+
this.nameCommitter = commit.committer.name;
295+
296+
this.apiService.getGithubUserData(commit.author.username).subscribe((evt: any) => {
297+
if (evt.status === 200) {
298+
const body = JSON.parse(evt._body);
299+
this.authorAvatar = body.avatar_url;
300+
}
301+
});
302+
} else {
303+
this.authorAvatar = this.committerAvatar;
304+
this.nameCommitter = this.nameAuthor;
305+
}
306+
} else if (this.build.data.pull_request) {
307+
this.authorAvatar = this.build.data.sender.avatar_url;
308+
this.committerAvatar = this.authorAvatar;
280309

281-
if (this.build.data.sha) {
282-
const data = this.build.data;
283-
this.committerAvatar = data.committer.avatar_url;
284-
this.nameCommitter = data.commit.committer.name;
285-
this.authorAvatar = data.author.avatar_url;
286-
this.nameAuthor = data.commit.author.name;
287-
} else if (this.build.data.head_commit) {
288-
const commit = this.build.data.head_commit;
289-
this.committerAvatar = this.build.data.sender.avatar_url;
290-
this.nameCommitter = this.build.data.head_commit.author.name;
291-
292-
if (commit.author.username !== commit.committer.username) {
293-
this.nameCommitter = commit.committer.name;
294-
295-
this.apiService.getGithubUserData(commit.author.username).subscribe((evt: any) => {
310+
this.apiService.getGithubUserData(this.build.data.sender.login).subscribe((evt: any) => {
296311
if (evt.status === 200) {
297312
const body = JSON.parse(evt._body);
298-
this.authorAvatar = body.avatar_url;
313+
this.nameAuthor = body.name;
299314
}
300315
});
301-
} else {
302-
this.authorAvatar = this.committerAvatar;
303-
this.nameCommitter = this.nameAuthor;
304-
}
305-
} else if (this.build.data.pull_request) {
306-
this.authorAvatar = this.build.data.sender.avatar_url;
307-
this.committerAvatar = this.authorAvatar;
308-
309-
this.apiService.getGithubUserData(this.build.data.sender.login).subscribe((evt: any) => {
310-
if (evt.status === 200) {
311-
const body = JSON.parse(evt._body);
312-
this.nameAuthor = body.name;
313-
}
314-
});
315316

316-
this.apiService.getGithubUserData(this.build.data.pull_request.user.login).subscribe((evt: any) => {
317-
if (evt.status === 200) {
318-
const body = JSON.parse(evt._body);
319-
this.nameCommitter = body.name;
320-
}
321-
});
322-
}
323-
324-
// bitbucket
325-
if (this.build.data.actor) {
326-
this.authorAvatar = this.build.data.actor.links.avatar.href;
327-
this.nameAuthor = this.build.data.actor.display_name;
328-
}
329-
330-
if (this.build.data.push) {
331-
this.commitMessage = this.build.data.push.changes[0].commits[0].message;
332-
this.dateTime = this.build.data.push.changes[0].commits[0].date;
333-
this.committerAvatar = this.build.data.push.changes[0].commits[0].author.user.links.avatar.href;
334-
this.nameCommitter = this.build.data.push.changes[0].commits[0].author.user.display_name;
335-
} else if (this.build.data.pullrequest) {
336-
this.commitMessage = data.pullrequest.description;
337-
this.dateTime = data.pullrequest.updated_on;
338-
this.committerAvatar = data.pullrequest.author.links.avatar.href;
339-
this.nameAuthor = data.pullrequest.author.display_name;
340-
this.nameCommitter = this.nameAuthor;
341-
}
317+
this.apiService.getGithubUserData(this.build.data.pull_request.user.login).subscribe((evt: any) => {
318+
if (evt.status === 200) {
319+
const body = JSON.parse(evt._body);
320+
this.nameCommitter = body.name;
321+
}
322+
});
323+
}
324+
} else if (this.build.repository.repository_provider === 'bitbucket') {
325+
// bitbucket
326+
if (this.build.data.actor) {
327+
this.authorAvatar = this.build.data.actor.links.avatar.href;
328+
this.nameAuthor = this.build.data.actor.display_name;
329+
}
342330

343-
// gitlab
344-
if (data.user_avatar) {
345-
this.authorAvatar = data.user_avatar;
346-
this.commitMessage = data.commits[0].message;
347-
this.dateTime = data.commits[0].timestamp;
348-
this.committerAvatar = this.authorAvatar;
349-
this.nameAuthor = data.user_name;
350-
this.nameCommitter = data.commits[0].author.name;
351-
}
331+
if (this.build.data.push) {
332+
this.commitMessage = this.build.data.push.changes[0].commits[0].message;
333+
this.dateTime = this.build.data.push.changes[0].commits[0].date;
334+
this.committerAvatar = this.build.data.push.changes[0].commits[0].author.user.links.avatar.href;
335+
this.nameCommitter = this.build.data.push.changes[0].commits[0].author.user.display_name;
336+
} else if (this.build.data.pullrequest) {
337+
this.commitMessage = data.pullrequest.description;
338+
this.dateTime = data.pullrequest.updated_on;
339+
this.committerAvatar = data.pullrequest.author.links.avatar.href;
340+
this.nameAuthor = data.pullrequest.author.display_name;
341+
this.nameCommitter = this.nameAuthor;
342+
}
343+
} else if (this.build.repository.repository_provider === 'gitlab') {
344+
// gitlab
345+
if (data.user_avatar) {
346+
this.authorAvatar = data.user_avatar;
347+
this.commitMessage = data.commits[0].message;
348+
this.dateTime = data.commits[0].timestamp;
349+
this.committerAvatar = this.authorAvatar;
350+
this.nameAuthor = data.user_name;
351+
this.nameCommitter = data.commits[0].author.name;
352+
} else if (data.object_attributes) {
353+
this.authorAvatar = data.user.avatar_url;
354+
this.commitMessage = data.object_attributes.last_commit.message;
355+
this.dateTime = data.object_attributes.last_commit.timestamp;
356+
this.committerAvatar = this.authorAvatar;
357+
this.nameAuthor = data.user.name;
358+
this.nameCommitter = data.object_attributes.last_commit.author.name;
359+
}
360+
} else if (this.build.repository.repository_provider === 'gogs') {
361+
// gogs
362+
if (data.pusher) {
363+
this.authorAvatar = data.pusher.avatar_url;
364+
this.nameAuthor = data.pusher.username;
365+
}
352366

353-
// gogs
354-
if (data.sender && data.pusher) {
355-
this.authorAvatar = data.pusher.avatar_url;
356-
this.nameAuthor = data.pusher.username;
357-
this.commitMessage = data.commits[0].message;
358-
this.dateTime = data.commits[0].timestamp;
359-
this.committerAvatar = data.sender.avatar_url;
360-
this.nameCommitter = data.sender.username;
367+
if (data.sender) {
368+
this.commitMessage = data.commits[0].message;
369+
this.dateTime = data.commits[0].timestamp;
370+
this.committerAvatar = data.sender.avatar_url;
371+
this.nameCommitter = data.sender.username;
372+
} else if (data.pull_request) {
373+
this.authorAvatar = data.pull_request.user.avatar_url;
374+
this.nameAuthor = data.pull_request.user.username;
375+
this.commitMessage = data.pull_request.title;
376+
this.dateTime = data.pull_request.head_repo.updated_at;
377+
}
361378
}
362379

363380
this.timerSubscription = this.timeService.getCurrentTime().subscribe(time => {

src/app/components/app-build-item/app-build-item.component.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<img *ngIf="authorAvatar" [src]="authorAvatar" class="avatar-img">
55
<img *ngIf="authorAvatar && committerAvatar && authorAvatar !== committerAvatar" [src]="committerAvatar" class="avatar-small">
66
</span>
7-
<span *ngIf="!build?.pr && !tag" class="bold larger">#{{ build?.id }}</span>
8-
<span *ngIf="build?.pr && !tag" class="bold larger">PR #{{ build?.pr }}</span>
7+
<span *ngIf="!build?.pr && build?.data?.object_kind !== 'merge_request' && !build?.data?.pull_request && !tag" class="bold larger">#{{ build?.id }}</span>
8+
<span *ngIf="(build?.pr && !build?.data?.object_kind) && !build?.data?.pull_request && !tag" class="bold larger">PR #{{ build?.pr }}</span>
9+
<span *ngIf="build?.data?.object_kind === 'merge_request' && !build?.data?.pull_request && !tag" class="bold larger">PR #{{ build?.data?.object_attributes?.iid }}</span>
10+
<span *ngIf="build?.data?.pull_request && !tag" class="bold larger">PR #{{ build?.data?.pull_request?.number }}</span>
911
<span *ngIf="tag" class="bold larger">{{ tag }}</span>
1012
</div>
1113
<div class="column is-2">
@@ -29,6 +31,7 @@
2931
<span class="bold" *ngIf="!build?.data?.pull_request?.head?.sha && !build?.data?.after && !build?.data?.sha && build?.data?.object_attributes?.last_commit?.id">{{ build?.data?.object_attributes?.last_commit?.id }}</span>
3032
<span class="bold" *ngIf="build?.data?.push?.changes">{{ build?.data?.push?.changes[0].commits[0].hash }}</span>
3133
<span class="bold" *ngIf="build?.data?.pullrequest">{{ build?.data?.pullrequest?.source?.commit?.hash }}</span>
34+
<span class="bold" *ngIf="build?.data?.pull_request">{{ build?.data?.pull_request?.source?.commit?.hash }}</span>
3235

3336
<span>{{ commitMessage }}</span>
3437

@@ -41,6 +44,7 @@
4144
<span *ngIf="tag">{{ build?.data?.head_commit?.comitter?.name }}</span>
4245
<span *ngIf="build?.data?.user_name">{{ build?.data?.user_name }}</span>
4346
<span *ngIf="build?.data?.pusher">{{ build?.data?.pusher?.username }}</span>
47+
<span *ngIf="build?.data?.pull_request">{{ build?.data?.pull_request?.user?.username }}</span>
4448
</div>
4549
<div class="column is-1">
4650
<span class="build-time" *ngIf="build?.status === 'running' && build?.maxCompletedJobTime && build?.minRunningJobStartTime && build?.maxCompletedJobTime > (currentTime - build?.minRunningJobStartTime)">{{ build?.maxCompletedJobTime | toTime }} </span>

0 commit comments

Comments
 (0)