oxsecurity / megalinter

🦙 MegaLinter analyzes 50 languages, 22 formats, 21 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.
https://megalinter.io
GNU Affero General Public License v3.0
1.93k stars 237 forks source link

Updated sources automatically commit to Azure DevOps PR #4153

Open lukelloydagi opened 2 weeks ago

lukelloydagi commented 2 weeks ago

Describe the solution you'd like When APPLY_FIXES: all is set in Azure Pipeline it would be useful for the automatically fixed files to be committed to the PR

image

Would it be better to have this as a toggle/environment variable to allow users to select what works for them?

Where would you go about implementing this? An existing file or a new separate file? If new how would that integrate to existing process?

nvuillam commented 2 weeks ago

@lukelloydagi APPLY_FIXES only work with GitHub Actions, because it's based on other workflows

https://github.com/oxsecurity/megalinter/blob/c116434995ccc05fd6918bb8373e09f17fc5e26d/mega-linter-runner/generators/mega-linter/templates/mega-linter.yml#L154 (from line 154 to end)

It is probably possible to do the same with Azure Pipelines, would you like to give it a try ? :)

I didn't find some "git commit" task in out of the box azure tasks ( https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/?view=azure-pipelines ) but there is probably one somehere, otherwise we can also use custom bash to make the commit & push, but i'd prefer something maintained somewhere else that in each MegaLinter pipeline :D

Maybe in custom tasks on MarketPlace ? https://marketplace.visualstudio.com/search?term=git&target=AzureDevOps&category=Azure%20Pipelines&cost=free&sortBy=Relevance

Then, we just need to find a way for MegaLinter step to output the info that there are updates to apply or not

lukelloyd1985 commented 2 weeks ago

You're already using the git Python package by the looks of it for the git diff: https://github.com/oxsecurity/megalinter/blob/c116434995ccc05fd6918bb8373e09f17fc5e26d/megalinter/MegaLinter.py#L797

Could use it again I imagine to do a repo.git.add etc if changed files are copied back to the root first?

nvuillam commented 2 weeks ago

@lukelloyd1985 it looks worth trying, and if it works it would also be applicable to Gitlab & Bitbucket :)

I can't remember why we did it externally ^^

lukelloyd1985 commented 2 weeks ago

Would you add code to megalinter/reporters/UpdatedSourcesReporter.py as that file seems to be doing the file moving or elsewhere as that's only a reporter?

nvuillam commented 2 weeks ago

Reporters can do things if they are configured to :)

lukelloyd1985 commented 2 weeks ago

Next silly question...😉

How would I go about testing changes to that file? Can I somehow get a docker image created for testing in my Azure Pipeline or just get that file injected somewhere somehow?

nvuillam commented 2 weeks ago

Make a PR to alpha branch then i'll be able to generate a MegaLinter alpha :)

lukelloyd1985 commented 11 hours ago

@nvuillam, it's only gone and worked 😲😆

image

I'll do some dotting of i's and crossing of t's and raise a PR to beta. Is there anyone who has experience of Bitbucket who can test?