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

Move all Git commands behind a PlatformScm interface #19065

Closed
NiasSt90 opened this issue Nov 24, 2022 · 9 comments · Fixed by #19327
Closed

Move all Git commands behind a PlatformScm interface #19065

NiasSt90 opened this issue Nov 24, 2022 · 9 comments · Fixed by #19327
Labels
platform:gerrit Gerrit Platform priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:refactor Refactoring or improving of existing code

Comments

@NiasSt90
Copy link
Contributor

Describe the proposed change(s).

To allow to support new platforms (like Gerrit #4109) which are not based on Git or use Git in a different way we need to abstract the current use of Git behind a new Interface PlatformScm.

All (most?) current exported functions from the util/git module defines the size/scope of the Interface (perhaps with some renaming).
The util/git module will be the default implementation for the existing platforms.

export interface Platform {
....
  //commitFiles?(config: CommitFilesConfig): Promise<CommitSha | null>;
  scmApi():PlatformScm;
}

export interface PlatformScm {
  initRepo(args: StorageConfig): Promise<void>;
  setAuthor(author: string | undefined): void;
  resetToCommit(commit: string): Promise<void>;
  branchExists(branchName: string): boolean;
  checkoutBranch(branchName: string): Promise<CommitSha>;
  isBranchBehindBase(branchName: string, baseBranch: string): Promise<boolean>
  isBranchModified(branchName: string): Promise<boolean>;
  commitFiles?(config: CommitFilesConfig): Promise<CommitSha | null>;
  //...TODO
}
@NiasSt90 NiasSt90 added priority-5-triage status:requirements Full requirements are not yet known, so implementation should not be started type:refactor Refactoring or improving of existing code labels Nov 24, 2022
@rarkins
Copy link
Collaborator

rarkins commented Nov 24, 2022

If our platforms were class based it would make this a lot easier. e.g. the base class could default to passing directly through to git if the function is not overridden in the platform. Either way I would prefer not to add 8+ functions to the existing platforms which aren't relevant, so we should try to wrap/centralize it

@NiasSt90
Copy link
Contributor Author

Perhaps we could separate the SCM implementation similar to the the current (platform) api implementation (platform/api.ts).

Not behind the platform interface it exists besides the platform interface. Then no need to change any existing platform module (i.e. export the util/git module as default scm()).

const scm = new Map<string, PlatformScm>();
export default scm;

scm.set('azure', gitScm);
...
scm.set('gerrit', gerrit);
scm.set('mercurial', mercurial);

Then the option platformCommit=true should switch from gitScm to githubScm (example names).

@rarkins
Copy link
Collaborator

rarkins commented Nov 24, 2022

Yes, good idea

NiasSt90 added a commit to intentus-GmbH/renovate that referenced this issue Nov 29, 2022
@NiasSt90
Copy link
Contributor Author

I've created a proof of concept (commit) and would like to get some feedback about the details.

The commit is on-top of the current Gerrit-PR only to show(validate) the usage of partial overriding the (default) PlatformSCM interface.
It will be separated if the proof-of-concept was done.

Currently it's allowed to partially override functions.
If not overridden the defaultGitScm implementation will be called (current util/git module).

@rarkins
Copy link
Collaborator

rarkins commented Nov 30, 2022

This looks ok to me. @viceice @JamieMagee what do you think about this approach vs putting everything behind platform.?

@viceice
Copy link
Member

viceice commented Nov 30, 2022

the general idea looks ok, but i've some annotations. So best is to create a draft PR where we can add those.

@JamieMagee
Copy link
Contributor

Yeah, I like this idea (and going towards interfaces + classes for all other modules like datasources). It would also help any implementation of #18094

NiasSt90 added a commit to intentus-GmbH/renovate that referenced this issue Dec 9, 2022
…tebot#19065

current state: six "util/git" functions are "moved" behind the PlatformSCM interface.
more to follow...
@NiasSt90
Copy link
Contributor Author

NiasSt90 commented Dec 9, 2022

I've added the Draft-PR now without the Gerrit-part (stripped off) and six functions already moved behind the interface.

It looks like on Github there is currently no option to create (or move) a pull-request on-top of another.
What is the best way to continue with the Gerrit-PullRequest?
Wait until this one here is finished and merged?

@HonkingGoose HonkingGoose added priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others and removed priority-5-triage labels Dec 12, 2022
@renovate-release
Copy link
Collaborator

🎉 This issue has been resolved in version 34.150.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
@viceice viceice added the platform:gerrit Gerrit Platform label Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform:gerrit Gerrit Platform priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:refactor Refactoring or improving of existing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants