I need help on how to successfully create a RepositoryMergeRequestCheck
As part of our merge workflow, we need to ensure some policies about some files. Policies includes among others:
- File naming conventions of individual files
- File naming conventions between multiple files (for example, correlative-named files)
- Inspection of files to enforce or disallow usage of statements or functions
I want to be able to check for this policies on a repository merge request check so I’m building a plugin for Astlassian Stash
I have tried the following approaches:
Using the
RepositoryMergeRequestCheckContext
parameter ofRepositoryMergeRequestCheck.check()
Since the method signature is:@Override public void check(RepositoryMergeRequestCheckContext context)
The first thing I tried using was the context parameter. I can say context.getMergeRequest().getPullRequest().getFromRef().getRepository()
Now I get a Repository instance and I’m not sure how to extract commit info from it.
Calling Git directly: Since this check was originally developed as a git hook script, calling git from the SDK made sense to me. It led me to this situation:
String result = gitScm.getCommandBuilderFactory().builder().lsTree().build(…).call();
Where gitScm gets dependency injected in the plugin’s constructor.
Notice the build parameter? It expects a CommandOutputHandler<T>
in this case T is string, but that’s an interface, and I’m not sure how to get an instance that implements that interface or how to create one.
- REST API REST API looks the easiest of them but it still doesn’t help with the third requirement of inspecting file’s source code and also, spawning web requests from the merge request check that is itself a web request from stash doesn’t seem to be a good idea from the performance side.
What path should I follow or how can I do it?