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

Don't do commit message checks on merges? #1099

Closed
delboy1978uk opened this issue Jul 18, 2023 · 8 comments
Closed

Don't do commit message checks on merges? #1099

delboy1978uk opened this issue Jul 18, 2023 · 8 comments

Comments

@delboy1978uk
Copy link
Contributor

Q A
Version latest
Bug? no
New feature? no
Question? yes
Documentation? no
Related tickets

Is there a way of NOT doing the Git Commit Message checks when doing a merge? It works great for us on our ticket branches, and we also have a hook adding the ticket number automatically from the branch name, but when we are on develop or master, there is no ticket number, so when we merge it doesn't like it!

@veewee
Copy link
Contributor

veewee commented Jul 19, 2023

That could be a nice addition to the task.
There is some sense of merge commit detection already, but we could add a flag to skip the task on merge commits.
Care to give it a try?

@delboy1978uk
Copy link
Contributor Author

@veewee sure, can you point me to the code I should be looking at?

@veewee
Copy link
Contributor

veewee commented Jul 19, 2023

The code for this specific task is located here:
https://github.com/phpro/grumphp/blob/v2.x/src/Task/Git/CommitMessage.php

Currently, there is a merge matching mechanism for skipping validation on scope conventions:

$mergePattern =
'(Merge branch|tag \'.+\'(?:\s.+)?|Merge remote-tracking branch \'.+\'|Merge pull request #\d+\s.+)';
if (count($types) > 0) {
$types = implode('|', $types);
$typesPattern = '(' . $types . ')';
}
if (count($scopes) > 0) {
$scopes = implode('|', $scopes);
$scopesPattern = '(:\s|(\((?:' . $scopes . ')\)?:\s))';
}
$rule = '/^' . $specialPrefix . $typesPattern . $scopesPattern . $subjectPattern . '|' . $mergePattern . '/';
try {
$this->runMatcher($config, $subjectLine, $rule, 'Invalid Type/Scope Format');
} catch (RuntimeException $e) {
throw $e;
}

It might make sense to extract these merge patterns into a separate function so that it can be used to determine if the task needs to run at all. You could use that same check to skip running the scope conventions.

That specific task is becoming a bit messy because of historical reasons and is open for improvements :)

@delboy1978uk
Copy link
Contributor Author

Thanks @veewee I'll have a look!
BTW I see you're in Belgium, me too! (ik woon al 7 jaar in Leuven)

@veewee
Copy link
Contributor

veewee commented Jul 19, 2023

Nice :) (Ik ben van de Kempen!)

@delboy1978uk
Copy link
Contributor Author

I'm now able to merge without a JIRA number on a merge! But let me know if I should move that is merge commit check further up or down the chain of events, I allowed it to still go through the first rules, like not empty message etc. Also, you mentioned a flag setting so we can have the merge skip enabled or disabled, how/where do we go about adding the setting?

@delboy1978uk
Copy link
Contributor Author

Of course, I have broken your tests in doing this :P But I'll wait for your feedback first before continuing work!

@veewee
Copy link
Contributor

veewee commented Jul 19, 2023

Cool. Let's continue the discussion in the PR.

@veewee veewee closed this as completed Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants