Changeset 211388 in webkit


Ignore:
Timestamp:
Jan 30, 2017 3:03:27 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add support for Trac instances that host multiple projects.
https://bugs.webkit.org/show_bug.cgi?id=167524

Patch by Kocsen Chung <Kocsen Chung> on 2017-01-30
Reviewed by Alexey Proskuryakov.

When multiple projects are hosted on a single Trac instance, the current
behavior will retrieve changesets from all tracked projects.
This patch teaches Trac.js to get project-specific changesets from Trac.
We do this by replacing the parameter changeset=on to repo-projectname=on
when querying the Trac timeline.

To tell Trac to be aware of multi-project instances we leverage the
options parameter when creating a new instance:

new Trac("https://mytrac.com/", { projectIdentifier: "tracProjectName" });

If this option is not provided, the original behaviour will prevail.
Additionally, add corresponding tests.

  • BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js:

(Trac): Reason about new optional parameter 'projectIdentifier'.
(Trac.prototype.revisionURL): Given a projectIdentifier, append it to the end of the URL.
(Trac.prototype._xmlTimelineURL): Given a projectIdentifier,
replace default parameter changeset=on with repo-projectname=on.
(Trac.prototype._convertCommitInfoElementToObject): Fix missing ';'.

  • BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/resources/MockTrac.js:

(MockTrac): Add support for instantiating Trac with a projectIdentifier.

  • BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/resources/tests.js:

(setup): Provide a multiple-project MockTrac instance to all test cases for testing.
Add the following tests:

test("revisionURL")
test("revisionURL with Trac Identifier")
test("_xmlTimelineURL")
test("_xmlTimelineURL with Trac Identifier")

(this.view._latestProductiveIteration): Fix missing ';'.

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js

    r196402 r211388  
    3131
    3232    this.baseURL = baseURL;
    33     this._needsAuthentication = (typeof options === "object") && options[Trac.NeedsAuthentication] === true;
     33    if (typeof options === "object") {
     34        this._needsAuthentication = options[Trac.NeedsAuthentication] === true;
     35        // We expect the projectIdentifier option iff the target Trac instance is hosting multiple repositories && Trac version > 1.0
     36        this._projectName = options[Trac.ProjectIdentifier];
     37    }
    3438
    3539    this.recordedCommits = []; // Will be sorted in ascending order.
     
    4145
    4246Trac.NeedsAuthentication = "needsAuthentication";
     47Trac.ProjectIdentifier = "projectIdentifier";
    4348Trac.UpdateInterval = 45000; // 45 seconds
    4449
     
    104109    revisionURL: function(revision)
    105110    {
    106         return this.baseURL + "changeset/" + encodeURIComponent(revision);
     111        var url = this.baseURL + "changeset/" + encodeURIComponent(revision);
     112        if (this._projectName)
     113            url += '/' + encodeURIComponent(this._projectName);
     114        return url;
    107115    },
    108116
     
    113121        var fromDay = new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate());
    114122        var toDay = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate());
    115 
    116         return this.baseURL + "timeline?changeset=on&format=rss&max=0" +
    117             "&from=" +  toDay.toISOString().slice(0, 10) +
    118             "&daysback=" + ((toDay - fromDay) / 1000 / 60 / 60 / 24);
     123        var changesetParameter = this._projectName ? "repo-" + this._projectName : "changeset";
     124
     125        return this.baseURL + "timeline?" +
     126            changesetParameter + "=on" +
     127            "&format=rss" +
     128            "&max=0" +
     129            "&from=" + encodeURIComponent(toDay.toISOString().slice(0, 10)) +
     130            "&daysback=" + encodeURIComponent((toDay - fromDay) / 1000 / 60 / 60 / 24);
    119131    },
    120132
     
    151163        if (parsedDescription.firstChild && parsedDescription.firstChild.className === "changes") {
    152164            // We can extract branch information when trac.ini contains "changeset_show_files=location".
    153             location = doc.evaluate("//strong", parsedDescription.firstChild, null, XPathResult.STRING_TYPE).stringValue
     165            location = doc.evaluate("//strong", parsedDescription.firstChild, null, XPathResult.STRING_TYPE).stringValue;
    154166            parsedDescription.removeChild(parsedDescription.firstChild);
    155167        }
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/resources/MockTrac.js

    r199180 r211388  
    2424 */
    2525
    26 MockTrac = function()
     26MockTrac = function(projectIdentifier)
    2727{
    28     Trac.call(this, "https://trac.webkit.org/");
     28    if (projectIdentifier) {
     29        var options = { };
     30        options[Trac.ProjectIdentifier] = projectIdentifier;
     31        Trac.call(this, "https://trac.webkit.org/", options);
     32    } else {
     33        Trac.call(this, "https://trac.webkit.org/");
     34    }
    2935};
    3036
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/resources/tests.js

    r201475 r211388  
    4242    setup: function() {
    4343        this.trac = new MockTrac();
     44        this.tracWithIdentifier = new MockTrac("webkit");
    4445    }
    4546});
     
    120121    var commits = this.trac.commitsOnBranchInRevisionRange("trunk", "33020", "33022");
    121122    equal(commits.length, 2, "in range 33020, 33022");
     123});
     124
     125test("revisionURL", function()
     126{
     127    strictEqual(this.trac.revisionURL("33020"), "https://trac.webkit.org/changeset/33020", "changeset URL matches for 33020");
     128    strictEqual(this.trac.revisionURL("0e498db5d8e5b5a342631"), "https://trac.webkit.org/changeset/0e498db5d8e5b5a342631", "changeset URL matches for 0e498db5d8e5b5a342631");
     129});
     130
     131test("revisionURL with Trac Identifier", function()
     132{
     133    strictEqual(this.tracWithIdentifier.revisionURL("33020"), "https://trac.webkit.org/changeset/33020/webkit", "changeset URL matches for 33020");
     134    strictEqual(this.tracWithIdentifier.revisionURL("0e498db5d8e5b5a342631"), "https://trac.webkit.org/changeset/0e498db5d8e5b5a342631/webkit", "changeset URL matches for 0e498db5d8e5b5a342631");
     135});
     136
     137test("_xmlTimelineURL", function()
     138{
     139    var before = new Date("1/1/2017");
     140    var after = new Date("1/2/2017");
     141
     142    strictEqual(this.trac._xmlTimelineURL(before, before), "https://trac.webkit.org/timeline?changeset=on&format=rss&max=0&from=2017-01-01&daysback=0");
     143    strictEqual(this.trac._xmlTimelineURL(before, after), "https://trac.webkit.org/timeline?changeset=on&format=rss&max=0&from=2017-01-02&daysback=1");
     144});
     145
     146test("_xmlTimelineURL with Trac Identifier", function()
     147{
     148    var before = new Date("1/1/2017");
     149    var after = new Date("1/2/2017");
     150
     151    strictEqual(this.tracWithIdentifier._xmlTimelineURL(before, before), "https://trac.webkit.org/timeline?repo-webkit=on&format=rss&max=0&from=2017-01-01&daysback=0");
     152    strictEqual(this.tracWithIdentifier._xmlTimelineURL(before, after), "https://trac.webkit.org/timeline?repo-webkit=on&format=rss&max=0&from=2017-01-02&daysback=1");
    122153});
    123154
     
    180211        };
    181212        return iteration;
    182     }
     213    };
    183214    var element = document.createElement("div");
    184215    var popover = new Dashboard.Popover();
  • trunk/Tools/ChangeLog

    r211382 r211388  
     12017-01-30  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Add support for Trac instances that host multiple projects.
     4        https://bugs.webkit.org/show_bug.cgi?id=167524
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        When multiple projects are hosted on a single Trac instance, the current
     9        behavior will retrieve changesets from all tracked projects.
     10        This patch teaches Trac.js to get project-specific changesets from Trac.
     11        We do this by replacing the parameter `changeset=on` to `repo-projectname=on`
     12        when querying the Trac timeline.
     13
     14        To tell Trac to be aware of multi-project instances we leverage the
     15        `options` parameter when creating a new instance:
     16
     17            new Trac("https://mytrac.com/", { projectIdentifier: "tracProjectName" });
     18
     19        If this option is not provided, the original behaviour will prevail.
     20        Additionally, add corresponding tests.
     21
     22        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Trac.js:
     23        (Trac): Reason about new optional parameter 'projectIdentifier'.
     24        (Trac.prototype.revisionURL): Given a projectIdentifier, append it to the end of the URL.
     25        (Trac.prototype._xmlTimelineURL): Given a projectIdentifier,
     26        replace default parameter `changeset=on` with `repo-projectname=on`.
     27        (Trac.prototype._convertCommitInfoElementToObject): Fix missing ';'.
     28        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/resources/MockTrac.js:
     29        (MockTrac): Add support for instantiating Trac with a projectIdentifier.
     30        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/resources/tests.js:
     31        (setup): Provide a multiple-project MockTrac instance to all test cases for testing.
     32        Add the following tests:
     33            test("revisionURL")
     34            test("revisionURL with Trac Identifier")
     35            test("_xmlTimelineURL")
     36            test("_xmlTimelineURL with Trac Identifier")
     37        (this.view._latestProductiveIteration): Fix missing ';'.
     38
    1392017-01-30  Myles C. Maxfield  <mmaxfield@apple.com>
    240
Note: See TracChangeset for help on using the changeset viewer.