commit api should not return 'AmbiguousRevisionPrefix' if there is an exact revision...
authordewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jun 2019 21:59:41 +0000 (21:59 +0000)
committerdewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jun 2019 21:59:41 +0000 (21:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199227

Reviewed by Ryosuke Niwa.

When prefix match is specified, api should check whether there is an exact match when multiple commits
match the prefix.

* public/include/commit-log-fetcher.php: Added the logic to check if there is an exact match when multiple matches are found.
* server-tests/api-commits-tests.js: Added an unit test.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246847 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/include/commit-log-fetcher.php
Websites/perf.webkit.org/server-tests/api-commits-tests.js

index ace89f2..b61419b 100644 (file)
@@ -1,3 +1,16 @@
+2019-06-26  Dewei Zhu  <dewei_zhu@apple.com>
+
+        commit api should not return 'AmbiguousRevisionPrefix' if there is an exact revision match
+        https://bugs.webkit.org/show_bug.cgi?id=199227
+
+        Reviewed by Ryosuke Niwa.
+
+        When prefix match is specified, api should check whether there is an exact match when multiple commits
+        match the prefix.
+
+        * public/include/commit-log-fetcher.php: Added the logic to check if there is an exact match when multiple matches are found.
+        * server-tests/api-commits-tests.js: Added an unit test.
+
 2019-06-24  Dean Johnson  <dean_johnson@apple.com>
 
         [perf.webkit.org] Update summary page calculations to use mean instead of median
index 0fd6df8..6e0becd 100644 (file)
@@ -201,11 +201,14 @@ class CommitLogFetcher {
     }
 
     private function commit_for_revision_prefix($repository_id, $revision_prefix) {
-        $rows = $this->db->query_and_fetch_all('SELECT * FROM commits WHERE commit_repository = $1 AND commit_revision LIKE $2 LIMIT 2', array($repository_id, Database::escape_for_like($revision_prefix) . '%'));
+        $rows = $this->db->query_and_fetch_all('SELECT * FROM commits WHERE commit_repository = $1 AND commit_revision LIKE $2 ORDER BY commit_revision LIMIT 2', array($repository_id, Database::escape_for_like($revision_prefix) . '%'));
         if (count($rows) == 0)
             exit_with_error('UnknownCommit', array('repository' => $repository_id, 'revision' => $revision_prefix));
-        if (count($rows) == 2)
+        if (count($rows) == 2) {
+            if ($rows[0]['commit_revision'] == $revision_prefix)
+                return $rows[0];
             exit_with_error('AmbiguousRevisionPrefix', array('repository' => $repository_id, 'revision' => $revision_prefix));
+        }
         return $rows[0];
     }
 
index 8bdade2..4344589 100644 (file)
@@ -39,6 +39,27 @@ describe("/api/commits/", function () {
         ]
     }
 
+    const commitsOnePrefixOfTheOther = {
+        "slaveName": "someSlave",
+        "slavePassword": "somePassword",
+        "commits": [
+            {
+                "repository": "WebKit",
+                "revision": "21094",
+                "time": "2017-01-20T02:52:34.577Z",
+                "author": {"name": "Zalan Bujtas", "account": "zalan@apple.com"},
+                "message": "a message",
+            },
+            {
+                "repository": "WebKit",
+                "revision": "210949",
+                "time": "2017-01-20T03:23:50.645Z",
+                "author": {"name": "Chris Dumez", "account": "cdumez@apple.com"},
+                "message": "some message",
+            }
+        ]
+    }
+
     const systemVersionCommits = {
         "slaveName": "someSlave",
         "slavePassword": "somePassword",
@@ -460,6 +481,16 @@ describe("/api/commits/", function () {
             assert.equal(result['status'], 'AmbiguousRevisionPrefix');
         });
 
+        it("should not return 'AmbiguousRevisionPrefix' when there is a commit revision extract matches specified revision prefix", async () => {
+            const remote = TestServer.remoteAPI();
+            await addSlaveForReport(commitsOnePrefixOfTheOther);
+            await remote.postJSONWithStatus('/api/report-commits/', commitsOnePrefixOfTheOther);
+            const result = await remote.getJSON('/api/commits/WebKit/21094?prefix-match=true');
+            assert.equal(result['status'], 'OK');
+            assert.deepEqual(result['commits'].length, 1);
+            assertCommitIsSameAsOneSubmitted(result['commits'][0], commitsOnePrefixOfTheOther['commits'][0]);
+        });
+
         it("should return 'UnknownCommit' when no commit is found for a revision prefix", async () => {
             const remote = TestServer.remoteAPI();
             await addSlaveForReport(subversionCommits);