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

Feature/gitlab integration #11105

Merged
merged 25 commits into from Sep 20, 2023

Conversation

e-stadnik
Copy link
Contributor

@e-stadnik e-stadnik commented Jul 16, 2023

Fixes #11104

Proposed changes

  • Added build server integration for Gitlab pipelines

Screenshots

Before

After

image

Test methodology

  • Unit tests for adapter logic are included
  • Manual testing on private commercial solution on self-hosted Gitlab instance
  • Manual testing on open-source repo: https://gitlab.com/wireshark/wireshark

Test environment(s)

  • GIT 2.33.0.windows.2
  • Windows 10 22H2 19045.3208

Merge strategy

  • To be decided later.

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned e-stadnik Jul 16, 2023
@e-stadnik e-stadnik marked this pull request as ready for review July 16, 2023 16:22
@gerhardol
Copy link
Member

Can this be tried with public gitlab.com?
What to configure?
Can you please add this to source/settings.rst?

Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

textboxes are wider than the the minimal width
very brief review but did not react to anything

GitExtensions.sln Outdated Show resolved Hide resolved
@RussKie
Copy link
Member

RussKie commented Jul 18, 2023 via email

@e-stadnik
Copy link
Contributor Author

Thank you for feedback and review tips.

As Gitlab mentioned in docs all significant API changes come major GitLab releases only. It should be very minor chance to receive unexpected failtures.

The logic here is quite simple and similar to other integrations included in main repo.

Can we discuss durability requirements which will make possible to merge it in product?
Because Gitlab.com allows token free access for public repos, I'm about to add integration tests.

@gerhardol
Copy link
Member

The logic here is quite simple and similar to other integrations included in main repo.

Can we discuss durability requirements which will make possible to merge it in product? Because Gitlab.com allows token free access for public repos, I'm about to add integration tests.

The difference is if any maintainer use the feature or not. (I have no info if someone uses TeamCity or if the integration exists). It is quite frustrating to get issue reports for features you know nothing about and cannot test.

Build server integration are quite special plugins, deeply integrated to GE so there are arguments to keep them in as well, then general cleanups are done as well.
@RussKie takes the decision.

@e-stadnik e-stadnik marked this pull request as draft July 23, 2023 08:56
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a visual:
image

Can you please describe how to use?
Can it be used with gitlab.com?

{
public class GitlabPipeline
{
public int id { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,21 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usings are not needed

Validates.NotNull(_apiClient);

PagedResponse<GitlabPipeline> firstPage = await _apiClient.GetPipelinesAsync(sinceDate, running, 1);
firstPage.Items.ForEach(item => ProcessLoadedBuild(item, observer));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RussKie will ask this to changed to a normal loop

@e-stadnik
Copy link
Contributor Author

Can you please describe how to use?
Can it be used with gitlab.com?

Sure, I tested on wireshark repo

For settings use Instance URL https://gitlab.com/
And project id 7898047
Token field can be left empty because it's a public project.

For private projects token can be obtained according to this guide

@pmiossec
Copy link
Member

Some potential improvements:

Can it be used with gitlab.com?

Sure, I tested on wireshark repo

So maybe it could be a good idea to set "https://gitlab.com" by default

For settings use Instance URL https://gitlab.com/ And project id 7898047 Token field can be left empty because it's a public project.

If projectId is mandatory but not the token, for me it makes more sense to put the projectId field before the token one.

For private projects token can be obtained according to this guide

I would at least put a link to this documentation. But even better looking at the documentation, you can build a link open the url (using the server url) to let the user easily create a token. From the doc https://gitlab.example.com/-/profile/personal_access_tokens?name=GitExtensions+Access+token&scopes=api,read_user,read_registry...
It is already done for the AzureDevOps Ci (TokenManagementLink control in SettingsUserControl.cs)

@e-stadnik
Copy link
Contributor Author

Philippe, thanks for your feedback!

I'm going to fill URL and project ID right from remotes.
Along with a link to obtain a token if necessary.

@pmiossec
Copy link
Member

I'm going to fill URL and project ID right from remotes.

Great!
But is it possible?
I don't know GitLab works but previously you said that you need the projectId 7898047 but you don't have it from the remote url ( https://gitlab.com/wireshark/wireshark.git).... There is a open api to get it?

@e-stadnik
Copy link
Contributor Author

But is it possible?

I'll try to lookup this way https://docs.gitlab.com/ee/api/projects.html#search-for-projects-by-name
When url_to_repo matches with remote it will be exact project id

@pmiossec
Copy link
Member

It's a little strange but with the request https://gitlab.com/api/v4/projects?search=wireshark&sort=asc I don't get the wireshark project in the list returned. We need a token to have the full list?

Note: Maybe the field path_with_namespace is better (but you will have to extract it from ssh or http urls...)

@RussKie
Copy link
Member

RussKie commented Jul 27, 2023 via email

@pmiossec
Copy link
Member

digital detox 😆

Mine starting in 2 days 😆

@e-stadnik
Copy link
Contributor Author

It's a little strange but with the request https://gitlab.com/api/v4/projects?search=wireshark&sort=asc I don't get the wireshark project in the list returned. We need a token to have the full list?

You see paged response. The target one can be somewhere deep.
But I've found other issue, that project can be renamed without changing remote path.

@pmiossec
Copy link
Member

But I've found other issue, that project can be renamed without changing remote path.

Yes, so don't add too much complexity for something that is only made once and takes 2 minutes to do.
Even me that don't know gitlab found it in 10s...

@e-stadnik
Copy link
Contributor Author

But I've found other issue, that project can be renamed without changing remote path.

Yes, so don't add too much complexity for something that is only made once and takes 2 minutes to do. Even me that don't know gitlab found it in 10s...

The solutions was easier
https://gitlab.com/api/v4/projects/wireshark%2Fwireshark returns whole project info.

@gerhardol
Copy link
Member

The ProjectId seems to be set for only one of the remotes. In my case I have "origin" with my changes and "upstream". The status is only shown for "origin".
AppVeyor and Jenkins at least allows several urls.

In addition, ProjectId is normally empty when opening the settings. I would like to say that the value is not read too, but it may be that I only got the build for origin but were looking for upstream builds.

@e-stadnik
Copy link
Contributor Author

e-stadnik commented Aug 7, 2023

I've never worked in multiple remotes with configured CI/CD on different servers.
But think Gitlab is mostly designed to operate with stages in a single project.
The stages are equivalent of build configurations in TeamCity terminology.

Maybe I miss some important case, but anyway to support pipeline statuses from multiple origins we should allow to set several instance URLs.

About ProjectId loading, it was bug, fixed :)

@gerhardol
Copy link
Member

Saving ProjectId seem to work for me now.

My question was about multiple owners on the same server, origin and upstream.
It is at least possible to switch between them now, so you can see builds from each even if it is hard to switch to upstream.
Not necessarily something to handle now.

I actually use multiple servers too. Not just different URL but different implementations for different suppliers: Gitlab to BitBucket to GitHub and back again.
But that is a separate setup, I use unique clones to handle this. Can unfortunately not use WorkTrees, GE does not store unique data per repo (not a big problem, build server is only important for me in BB). No private clones in BB, but multiple 'users' in GL.

@RussKie How to proceed here? Include this now and separate later?
If the plugin fails, it will have to wait for next normal update...

@spdr870
Copy link
Member

spdr870 commented Aug 8, 2023

@e-stadnik
I use the gitlab community edition, self-hosted. I tried this plugin. The status is visible. The biggest issue I have is the performance. The repository is over 200.000 commits, and the UI freezes until the status is fetched for, I assume, all commits? To make it workable, I changed the code only to load the first page. Not sure how other plugins work, but a limit would be needed for large repositories. And maybe check for cancellationToken.IsCancellationRequested when loading pages?

Also; the build report tab page couldn't load the content since the inline browser is not supported by gitlab. Not a problem for me, the link to open it in an external browser works.

@e-stadnik
Copy link
Contributor Author

@spdr870, Thanks a lot for you feedback!

Can you see page numbers on pipelines web page for you project?
From some threshold plugin loading all pages one by one, because total pages disappears from API as well. (like in wireshark repo). I didn't face with performance issues here.

If value for you project is below, plugin trying to request pages in parallel. In that case I'll try to change scheduler logic and it should helps with performance.

As constant solution I think to cache loaded entities on disk because API will return updated entities.

@spdr870
Copy link
Member

spdr870 commented Aug 8, 2023

Can you see page numbers on pipelines web page for you project?

No pagenumbers, just Next. I manually altered the URL to find the number of pipelines, I could go to page 3342:
http://gitlab/Development/*********/-/pipelines?page=3342&scope=all

We run ~80 pipelines per day
image

@gerhardol
Copy link
Member

The biggest issue I have is the performance. The repository is over 200.000 commits, and the UI freezes until the status is fetched for, I assume, all commits? To make it workable, I changed the code only to load the first page. Not sure how other plugins work, but a limit would be needed for large repositories. And maybe check for cancellationToken.IsCancellationRequested when loading pages?

Build status should be fetched and updated in the background (it is for at least Jenkins and AppVeyor).

Also; the build report tab page couldn't load the content since the inline browser is not supported by gitlab. Not a problem for me, the link to open it in an external browser works.

The tab should be disabled by default for all build servers.
The WebBrowser control could be replaced with WebView2 (https://learn.microsoft.com/en-us/microsoft-edge/webview2/) (only Win10 and later) or some Chromium control (adds to size), but I propose to just change the defaults.

@e-stadnik
Copy link
Contributor Author

I added BuildServer.Gitlab.PagesLimit settings but not sure about showing it in UI
It will appear in GitExtensions.settings file with default value (0 - no limitation) after save action in Gitlab settings page.
@spdr870 can you please check performance now with 10 or 50 pages?

@e-stadnik
Copy link
Contributor Author

e-stadnik commented Sep 18, 2023

Can this be tried with public gitlab.com? What to configure? Can you please add this to source/settings.rst?

UI fields documentation added here: gitextensions/GitExtensionsDoc#148

@gerhardol sorry for force pushed commit, didn't expect that it'll break review comments. Hope everything will be fine for now.

@gerhardol
Copy link
Member

@RussKie I suggest that this plugin is included. Separating buildserver plugins may be done later.

GetProjectIdLink.Location = new Point(82, 54);
GetProjectIdLink.Name = "GetProjectIdLink";
GetProjectIdLink.Size = new Size(749, 15);
GetProjectIdLink.TabIndex = 9;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please confirm the tab order is logically sequenced?

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Sep 20, 2023
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Sep 20, 2023
@RussKie
Copy link
Member

RussKie commented Sep 20, 2023

Here's a test artifact: https://ci.appveyor.com/project/gitextensions/gitextensions/builds/48079386/artifacts
Could you please take it for a spin, install it and see if everything is working as you expect? If everything is good, we'll merge this.
Thank you.

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Sep 20, 2023
@e-stadnik
Copy link
Contributor Author

I'd been testing build 4.2.0.17315 for a last 2 weeks on a private repo.

On recent build checked tabIndex and pages loading limitation. Everything looks fine.

@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Sep 20, 2023
@gerhardol
Copy link
Member

I have been using this pr for some time too, but my interaction with gitlab is quite limited, so it does not push any limit.
No proper review, but it looks good.

@RussKie RussKie merged commit cad0513 into gitextensions:master Sep 20, 2023
3 checks passed
@ghost ghost added this to the vNext milestone Sep 20, 2023
@RussKie
Copy link
Member

RussKie commented Sep 20, 2023

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gitlab pipelines build plugin
5 participants