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

Implement support for Gitea #264

Closed
wants to merge 15 commits into from
Closed

Conversation

belidzs
Copy link

@belidzs belidzs commented Jul 31, 2020

This is the PR to track the development of support for Gitea.

Description

It adds support specifically for Gitea by implementing GiteaProvider (an IVcsProvider descendant) but also expands the main code by adding capabilities to choose between and configure custom providers.

Related Issue

Issue #252

Motivation and Context

See linked issue

How Has This Been Tested?

It's currently manually tested against https://try.gitea.io which is a free and publicly available sandbox instance of Gitea.

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@belidzs
Copy link
Author

belidzs commented Jul 31, 2020

The client API is generated using the latest official API schema

The tool I've used is openapi-generator and the resulting code is in a separate repo which is currently locally referenced in the project.

The plan is to fix all the issues in the client API (the generator is far from being perfect) and when it's done (or at least good enough for use with GRM) publish it on NuGet and replace all the references to the public package.

@lgtm-com
Copy link

lgtm-com bot commented Jul 31, 2020

This pull request introduces 64 alerts when merging 68c2fc2 into 1c03234 - view on LGTM.com

new alerts:

  • 64 for Use of default ToString()

@gep13
Copy link
Member

gep13 commented Jul 31, 2020

@belidzs having the IVcsProvider is still likely to be needed. @akordowski has expressed an interest in adding DI to the project for other reason, and we are likely going to need that interface to allow this to happen. For what I think you want to do, I would suggest both an interface, and an abstract base class (with virtual methods). That way, we can provide default implementations of the internal methods, but which can be overridden when required.

Does that make sense?

Would be good to get some thoughts from @AdmiringWorm and @akordowski here.

@belidzs
Copy link
Author

belidzs commented Jul 31, 2020

@gep13 you're right it makes sense to use interfaces for that. I've recently started using DI in .NET Core and I really love the concept.

I've already started extracting some common stuff into the abstract class, however I have a feeling that probably I should use AutoMapper and pass complex model objects to functions instead of raw properties (e.g. a Model.Issue instead of index), but I'm not sure which one is the better solution.

Can you take a look at a6447c5 and confirm that this is the direction you had in mind regarding the inheritance?

@gep13
Copy link
Member

gep13 commented Jul 31, 2020

I was more thinking along the lines of:

public class GiteaProvider : VcsProviderBase, IVcsProvider

And then only having the overrideable methods in the VcsProviderBase class.

@belidzs
Copy link
Author

belidzs commented Jul 31, 2020

Wouldn't that be redundant? VcsProviderBase already has to inherit from the interface since it provides a default implementation of CreateLabels()

@gep13
Copy link
Member

gep13 commented Jul 31, 2020

VcsProviderBase doesn't need to inherit from IVcsProvider. The base class will only contain the methods that were private in the GitHubVcsProvider, with the default implementation, that can then be overridden if/when required.

Comment on lines 53 to 76
public virtual async Task CreateLabelsAsync(string owner, string repository)
{
if (Configuration.Labels.Any())
{
Logger.Verbose("Removing existing labels");
await DeleteExistingLabelsAsync(owner, repository).ConfigureAwait(false);
Logger.Verbose("Creating new standard labels");
var newLabelTasks = new List<Task>();
foreach (var label in Configuration.Labels)
{
newLabelTasks.Add(CreateLabelAsync(owner, repository, label));
}

await Task.WhenAll(newLabelTasks).ConfigureAwait(false);
}
else
{
Logger.Warning("No labels defined");
}
}

protected abstract Task DeleteExistingLabelsAsync(string owner, string repository);

protected abstract Task CreateLabelAsync(string owner, string repository, LabelConfig label);
Copy link
Author

Choose a reason for hiding this comment

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

This is an example of a public default implementation of an interface method which calls for two abstract protected methods.

It's completely possible that it is somehow anti-pattern, however it reduces redundant code quite a bit

@AdmiringWorm
Copy link
Member

@belidzs having the IVcsProvider is still likely to be needed. @akordowski has expressed an interest in adding DI to the project for other reason, and we are likely going to need that interface to allow this to happen.

We don't need to have an interface even when implementing DI. A abstract class would be just as valid instead of an interface. I don't care either way if there is an interface or an abstract base class that is being used.

@lgtm-com
Copy link

lgtm-com bot commented Jul 31, 2020

This pull request introduces 64 alerts when merging 293164c into 1c03234 - view on LGTM.com

new alerts:

  • 64 for Use of default ToString()

@akordowski
Copy link
Contributor

@belidzs I'm currently at the implementaion of the DI. I wouldn't put much effort into the VCsProvider before we have a stable and functioning DI implementaion. So you would avoid to fix the merge conflicts later.

@belidzs
Copy link
Author

belidzs commented Jul 31, 2020

@akordowski thanks for the heads up, I wasn't aware that there was anything else going on so I have already done some heavy refactoring on the GitHubProvider class. I hope I'll be able to escape from the merge hell after you've finished.

Can you let me know if you're done with GitHubProvider and IVcsProvider?

@akordowski
Copy link
Contributor

@belidzs I will publish a draft PR the comming days so we can discuss the next step. I will inform you then.

@belidzs
Copy link
Author

belidzs commented Jul 31, 2020

Cheers @akordowski

@belidzs belidzs marked this pull request as draft August 10, 2020 22:20
@belidzs
Copy link
Author

belidzs commented Oct 9, 2020

Is it safe to start working on this again?

@akordowski
Copy link
Contributor

Actually, yes. There are some pending PRs so at the end there might be some merge conflicts. But the refactorings for DI are already merged into the develop branch.

@mario-dg
Copy link

Any updates on this?

@belidzs
Copy link
Author

belidzs commented Apr 24, 2024

Sorry, but no as I don't use GitReleaseManager anymore

@belidzs belidzs closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants