Skip to content

Don't mention bugzilla for PRs #307

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
56 changes: 2 additions & 54 deletions source/dlangbot/bugzilla.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import vibe.inet.webform : urlEncode;
shared string bugzillaURL = "https://issues.dlang.org";

// D projects which use Bugzilla for bug tracking.
static immutable bugzillaProjectSlugs = ["dlang/dmd", "dlang/druntime", "dlang/phobos",
"dlang/dlang.org", "dlang/tools", "dlang/installer"];
static immutable bugzillaProjectSlugs = ["dlang/installer"];


import std.algorithm, std.conv, std.range, std.string;
Expand Down Expand Up @@ -95,65 +94,14 @@ struct IssueRef { int id; bool fixed; Json[] commits; }
// get all issues mentioned in a commit
IssueRef[] getIssueRefs(RE)(Json[] commits, RE re = issueRE)
{
return commits
// Collect all issue references (range of ranges per commit)
.map!(c => c["commit"]["message"]
.get!string
.matchIssueRefs(re)
.map!((r) { r.commits = [c]; return r; })
)
// Join to flat list
.join
// Sort and group by issue ID
.sort!((a, b) => a.id < b.id, SwapStrategy.stable)
.groupBy
// Reduce each per-ID group to a single IssueRef
.map!(g => g
.reduce!((a, b) =>
IssueRef(a.id, a.fixed || b.fixed, a.commits ~ b.commits)
)
)
.array;
}

unittest
{
Json fix(int id) { return ["commit":["message":"Fix Bugzilla %d".format(id).Json].Json].Json; }
Json mention(int id) { return ["commit":["message":"Bugzilla %d".format(id).Json].Json].Json; }

assert(getIssueRefs([fix(1)]) == [IssueRef(1, true, [fix(1)])]);
assert(getIssueRefs([mention(1)]) == [IssueRef(1, false, [mention(1)])]);
assert(getIssueRefs([fix(1), mention(1)]) == [IssueRef(1, true, [fix(1), mention(1)])]);
assert(getIssueRefs([mention(1), fix(1)]) == [IssueRef(1, true, [mention(1), fix(1)])]);
assert(getIssueRefs([mention(1), fix(2), fix(1)]) == [IssueRef(1, true, [mention(1), fix(1)]), IssueRef(2, true, [fix(2)])]);
return null;
}

UserMessage[] checkLegacyIssueRefs(Json[] commits)
{
auto oldHits = commits.getIssueRefs(oldIssueRE).map!(r => r.id);
auto newHits = commits.getIssueRefs(issueRE).map!(r => r.id);
auto onlyOld = oldHits.filter!(id => !newHits.canFind(id));
if (!onlyOld.empty)
return [UserMessage(UserMessage.Type.Warning,
"In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. " ~
"Please add the word \"Bugzilla\" to issue references. For example, `Fix Bugzilla Issue 12345` or `Fix Bugzilla 12345`." ~
"(Reminder: the edit needs to be done in the Git *commit message*, not the GitHub *pull request*.)"
)];
return null;
}

unittest
{
Json fixOld(int id) { return ["commit":["message":"Fix Issue %d".format(id).Json].Json].Json; }
Json fixNew(int id) { return ["commit":["message":"Fix Bugzilla %d".format(id).Json].Json].Json; }

assert( checkLegacyIssueRefs([]).empty);
assert( checkLegacyIssueRefs([fixNew(1)]).empty);
assert( checkLegacyIssueRefs([fixOld(1), fixNew(1)]).empty);
assert(!checkLegacyIssueRefs([fixOld(1)]).empty);
assert(!checkLegacyIssueRefs([fixOld(1), fixNew(2)]).empty);
}

struct Issue
{
int id;
Expand Down
Loading
Loading