Skip to content

Feat: Improvements for Do not Merge #56

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

Merged
merged 3 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Disables "Merge pull request" button while ANY of the following is true:

## Usage

* Put `[wip]` or `[WIP]` or `[Do Not Merge]` on the title of the pull request
* Put `[wip]` or `[WIP]` or `[Do Not Merge]` or `[DNM]` in the title of the pull request
or
* Add `wip`, `Do Not Merge` or `DNM` (Case insensitive) as a tag to your pull request
* It works!

## Changelog
Expand Down
4 changes: 3 additions & 1 deletion app/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ <h1 class="title">Do Not Merge WIP for GitHub</h1>
<form action="" class="options">
<div class="option">
<label for="protected_branch">Protected Branch <span class="weak">(Regular Expression)</span></label>
<input type="text" id="protected_branch" name="protected_branch" placeholder="e.g. deployment/*" />
<input type="text" id="protected_branch" name="protected_branch" placeholder="e.g. deployment/*" /><br />
<label for="button_message">Button Message <span class="weak">(String)</span></label>
<input type="text" id="button_message" name="button_message" placeholder="WIP! You can't merge!" />
</div>
<div class="buttons">
<button id="save_btn" class="button">Save</button>
Expand Down
24 changes: 21 additions & 3 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,32 @@
}
buttonHtml = '<span class="octicon octicon-git-branch-delete"></span> ' + (disabled ? 'Protected branch' : 'Delete branch');
} else {
var isWipTitle = /(\[wip\]|\[do\s*not\s*merge\])/i.test(issueTitle);
var wipTitleRegex = /(\[wip\]|\[do\s*not\s*merge\]|\[dnm\])/i;
var wipTagRegex = /(wip|do\s*not\s*merge|dnm)/i;

var isWipTitle = wipTitleRegex.test(issueTitle);
var isWipTaksList = $container.find('.timeline-comment:first input[type="checkbox"]:not(:checked)').length > 0;
var isSquashCommits = false;
$container.find('#commits_bucket .commit .commit-title').each(function(i, elem){
isSquashCommits = isSquashCommits || $(elem).text().match(/^\s*(squash|fixup)!\s/);
});
disabled = (isWipTitle || isWipTaksList || isSquashCommits);
buttonHtml = '<span class="octicon octicon-git-merge"></span> ' + (disabled ? 'WIP! You can\'t merge!' : 'Merge pull request');

var isWipTag = false;
$container.find('#discussion_bucket .labels .label').each(function(i, elem) {
isWipTag = isWipTag || $(elem).text().match(wipTagRegex);
});

disabled = (isWipTitle || isWipTaksList || isSquashCommits || isWipTag);

var buttonMessage = '';

if (localStorage && localStorage.buttonMessage) {
buttonMessage = localStorage.buttonMessage;
} else {
buttonMessage = 'WIP! You can\'t merge!';
}

buttonHtml = '<span class="octicon octicon-git-merge"></span> ' + (disabled ? buttonMessage : 'Merge pull request');
}

$buttonMerge.attr('disabled', disabled);
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
(function($){
$(function(){
$('#protected_branch').val(localStorage.protectedBranch);
$('#button_message').val(localStorage.buttonMessage);

$('#save_btn').closest('form').submit(function(e) {
e.preventDefault();
localStorage.protectedBranch = $('#protected_branch').val();
localStorage.buttonMessage = $('#button_message').val();

window.alert('The options have been saved!');
});
Expand Down