Configure Codacy to review all branches of a monitored branch?

699 Views Asked by At

Right now we have Codacy monitoring a DEV branch, and as per recommended practices, whenever we do something, we create a personal branch of DEV, work on that, and then merge back in. Thing is, if Codacy finds a problem, we have to branch out of DEV, revise, then merge back in again. Meanwhile, DEV has this defective code, so we have to undo that merge, etc, etc. Lots of room for error if you're panicking because the guys overseas are coming online soon!

Three acceptable solutions come to mind, might be more:

  • configure Codacy to review all branches of a monitored branch post-commit
  • we tend to name our branches consistently, so could specify regular expressions
  • configure GitHub and/or Codacy to prevent pulls of a monitored branch if there are pending Codacy issues

Are any of these possible?

2

There are 2 best solutions below

2
machadoit On

Under /settings/branches you can define "Branch protection rules" for DEV and make Codacy status as required. You will not be able to merge the PR until you handle your issues.

9
Tarun Lalwani On

As discussed follow the below approach

You should be restricting any pushes to DEV by making it a protected branch. No direct commits will be allowed and only through pull request commits can be merged. In the same, you can mandate the codacy checks to be passed for a merge to be allowed

See below settings for sample

Github settings

Update 12th Jul:

Lots of points clarified on comments, so adding those explanations to answer

Developer 1 -> Commits to DEV_1 Branch -> Raise a Pull Request #1 to Merge DEV_1 to DEV Developer 2 -> Commits to DEV_2 Branch -> Raise a Pull Request #2 to Merge DEV_2 to DEV

The PR #1 and PR#2 cannot be merged as we have specified that the codacy status check has to Pass.

This status check from Codacy, will do all the testing that you want to do. Once the Codacy test have passed it will update the PR and merging will get enabled based on the status of the Codacy results

The Codacy test is nothing but a Post commit check. Github doesn't allow pre-commit hooks. Gitlab does allow you to have pre-commit hooks but its best to use post-commit hooks on a PR when working with Github

Post hooks