Diff
Modified: trunk/Tools/ChangeLog (274522 => 274523)
--- trunk/Tools/ChangeLog 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/ChangeLog 2021-03-16 22:09:55 UTC (rev 274523)
@@ -1,3 +1,34 @@
+2021-03-16 Jonathan Bedard <[email protected]>
+
+ [resultsdbpy] Allow user to change commit representation
+ https://bugs.webkit.org/show_bug.cgi?id=223215
+ <rdar://problem/75446602>
+
+ Reviewed by Dewei Zhu.
+
+ * Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py: Bump version.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/controller/api_routes.py:
+ (APIRoutes.__init__): Add commit representations endpoint.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/controller/commit_controller.py:
+ (CommitController.representations): Add commit representations endpoint.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/model/repository.py:
+ (Repository.representations): Return prioritized commit representation.
+ (StashRepository.representations): Ditto.
+ (WebKitRepository.representations): Ditto.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/commit.js:
+ (Commit.prototype.label): Change the commit representation based on global settings.
+ (_CommitBank):
+ (_CommitBank.prototype.commitRepresentations): Check the commit representation cookie, then
+ the representation endpoint.
+ (_CommitBank.prototype.setCommitRepresentation): Set the commit representation cookie.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/drawer.js:
+ (CommitRepresentation): Drawer control allowing user to change commit representation for repositories.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/commits.html: Add new control.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/documentation.html: Ditto.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/search.html: Ditto.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/suite_results.html: Ditto.
+ * Scripts/libraries/resultsdbpy/setup.py: Bump version.
+
2021-03-16 Devin Rousso <[email protected]>
[macOS] change for the language/subtitle tracks button to use an `NSMenu` instead of web content
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py 2021-03-16 22:09:55 UTC (rev 274523)
@@ -44,6 +44,6 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(2, 0, 1)
+version = Version(2, 0, 2)
name = 'resultsdbpy'
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/controller/api_routes.py (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/controller/api_routes.py 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/controller/api_routes.py 2021-03-16 22:09:55 UTC (rev 274523)
@@ -55,6 +55,7 @@
self.add_url_rule('/commits', 'commit_controller', self.commit_controller.default, methods=('GET', 'POST'))
self.add_url_rule('/commits/find', 'commit_controller_find', self.commit_controller.find, methods=('GET',))
self.add_url_rule('/commits/repositories', 'commit_controller_repositories', self.commit_controller.repositories, methods=('GET',))
+ self.add_url_rule('/commits/representations', 'commit_controller_representations', self.commit_controller.representations, methods=('GET',))
self.add_url_rule('/commits/branches', 'commit_controller_branches', self.commit_controller.branches, methods=('GET',))
self.add_url_rule('/commits/siblings', 'commit_controller_siblings', self.commit_controller.siblings, methods=('GET',))
self.add_url_rule('/commits/next', 'commit_controller_next', self.commit_controller.next, methods=('GET',))
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/controller/commit_controller.py (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/controller/commit_controller.py 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/controller/commit_controller.py 2021-03-16 22:09:55 UTC (rev 274523)
@@ -191,6 +191,13 @@
AssertRequest.no_query()
return jsonify(sorted(self.commit_context.repositories.keys()))
+ def representations(self):
+ AssertRequest.is_type()
+ AssertRequest.no_query()
+ return jsonify({
+ key: repository.representations() for key, repository in self.commit_context.repositories.items()
+ })
+
@query_as_kwargs()
@limit_for_query(DEFAULT_LIMIT)
def branches(self, repository_id=None, branch=None, limit=None, **kwargs):
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/model/repository.py (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/model/repository.py 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/model/repository.py 2021-03-16 22:09:55 UTC (rev 274523)
@@ -36,7 +36,10 @@
def url_for_commit(self, commit):
return None
+ def representations(self):
+ return []
+
class StashRepository(Repository):
def __init__(self, url, key=None, default_branch=None):
@@ -61,7 +64,10 @@
def url_for_commit(self, commit):
return f'{self.remote.url}/commits/{commit}'
+ def representations(self):
+ return ['hash', 'identifier']
+
class WebKitRepository(Repository):
def __init__(self):
@@ -85,3 +91,6 @@
def url_for_commit(self, commit):
return f'https://commits.webkit.org/r{commit}'
+
+ def representations(self):
+ return ['identifier', 'revision']
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/commit.js (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/commit.js 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/commit.js 2021-03-16 22:09:55 UTC (rev 274523)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019, 2020 Apple Inc. All rights reserved.
+// Copyright (C) 2019-2021 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -147,11 +147,23 @@
return this.uuid - commit.uuid;
}
label() {
- // Per the birthday paradox, 10% chance of collision with 7.7 million commits with 12 character commits
- return this.identifier.substring(0,12);
+ const preference = CommitBank._representationCache ? CommitBank._representationCache[this.repository_id].representation : null;
+
+ if (preference === 'identifier')
+ return this.identifier;
+ if (preference === 'hash') {
+ // Per the birthday paradox, 10% chance of collision with 7.7 million commits with 12 character commits
+ return this.hash.substring(0,12)
+ }
+ if (preference === 'revision')
+ return `r${this.revision}`;
+
+ return this.revision ? `r${this.revision}` : this.hash.substring(0,12);
}
};
+const COOKIE_NAME = 'commitRepresentation';
+
class _CommitBank {
constructor() {
this.commits = [];
@@ -163,8 +175,46 @@
this._beginUuid = null;
this._endUuid = null;
this.callbacks = [];
+ this._representationCache = null;
+ }
+ commitRepresentations(callback) {
+ if (this._representationCache != null) {
+ callback(this._representationCache)
+ return;
+ }
+ const cookies = decodeURIComponent(document.cookie).split(';')
+ for (let index = 0; index < cookies.length; ++index) {
+ if (cookies[index].indexOf(`${COOKIE_NAME}=`))
+ continue;
+ this._representationCache = JSON.parse(cookies[index].substring(COOKIE_NAME.length + 1));
+ callback(this._representationCache);
+ return;
+ }
+
+ fetch('api/commits/representations').then(response => {
+ response.json().then(json => {
+ this._representationCache = {};
+ Object.keys(json).forEach(repository => {
+ if (!json[repository].length)
+ return;
+ this._representationCache[repository] = {
+ 'representation': json[repository][0],
+ 'candidates': json[repository],
+ }
+ });
+ document.cookie = `${COOKIE_NAME}=${JSON.stringify(this._representationCache)}`;
+ callback(this._representationCache);
+ });
+ }).catch(error => {
+ // If the load fails, log the error and continue
+ console.error(JSON.stringify(error, null, 4));
+ });
}
+ setCommitRepresentation(repository, representation) {
+ this._representationCache[repository].representation = representation;
+ document.cookie = `${COOKIE_NAME}=${JSON.stringify(this._representationCache)}`;
+ }
latest(params) {
this._branches = new Set(params.branch);
this._repositories = new Set(params.repository_id);
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/drawer.js (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/drawer.js 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/static/js/drawer.js 2021-03-16 22:09:55 UTC (rev 274523)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Apple Inc. All rights reserved.
+// Copyright (C) 2019-2021 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -22,7 +22,8 @@
// THE POSSIBILITY OF SUCH DAMAGE.
import {DOM, REF} from '/library/js/Ref.js';
-import {queryToParams, paramsToQuery, QueryModifier, } from '/assets/js/common.js';
+import {queryToParams, paramsToQuery, QueryModifier} from '/assets/js/common.js';
+import {CommitBank} from '/assets/js/commit.js';
import {Configuration} from '/assets/js/configuration.js'
function setEnableRecursive(element, state) {
@@ -331,4 +332,72 @@
}).join('')
}
-export {Drawer, BranchSelector, ConfigurationSelectors, LimitSlider};
+function CommitRepresentation(callback) {
+ const ref = REF.createRef({
+ state: {},
+ onStateUpdate: (element, state) => {
+ if (!Object.keys(state).length)
+ return;
+
+ DOM.inject(
+ element,
+ Object.keys(state).map(repository => {
+ const selector = REF.createRef({
+ state: state[repository].representation,
+ onElementMount: (element) => {
+ if (!element)
+ return;
+ element._onchange_ = () => {
+ CommitBank.setCommitRepresentation(repository, element.value);
+ callback();
+ }
+ },
+ onStateUpdate: (element, representation) => {
+ element.innerHTML = state[repository].candidates.map(candidate => {
+ if (candidate === representation)
+ return `<option selected value="${candidate}">${candidate}</option>`;
+ return `<option value="${candidate}">${candidate}</option>`;
+ }).join('');
+ },
+ });
+ return `<div class="input">
+ <select required ref="${selector}">
+ ${state[repository].candidates.map(repr => `<option value="${repr}">${repr}</option>`).join('')}
+ </select>
+ <label style="color:var(--inverseColor)">${repository.charAt(0).toUpperCase() + repository.slice(1)}</label>
+ </div>`;
+ }).join(''));
+ },
+ });
+ CommitBank.commitRepresentations(json => {
+ ref.setState(json);
+ });
+
+ const expander = REF.createRef({
+ state: {isExpanded: false},
+ onStateUpdate: (element, state) => {
+ element.innerHTML = state.isExpanded ? '-' : '+';
+
+ Array.from(element.parentNode.children).forEach(child => {
+ if (element == child)
+ return;
+ child.style.display = state.isExpanded ? 'block' : 'none';
+ });
+ },
+ });
+ expander.fromEvent('click').action(() => expander.setState({isExpanded: !expander.state.isExpanded}));
+
+ return `<div class="item">
+ <div style="font-size: var(--smallSize);">
+ <a class="link-button text medium" ref="${expander}">+</a>
+ Commit Representation
+ <div class="list" ref="${ref}" style="display: none;">
+ <div class="item loader">
+ <div class="spinner"></div>
+ </div>
+ </div>
+ </div>
+ </div>`;
+}
+
+export {Drawer, BranchSelector, ConfigurationSelectors, LimitSlider, CommitRepresentation};
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/commits.html (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/commits.html 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/commits.html 2021-03-16 22:09:55 UTC (rev 274523)
@@ -31,7 +31,7 @@
import {REF, DOM} from '/library/js/Ref.js';
import {ErrorDisplay} from '/assets/js/common.js';
import {Commit, CommitTable} from '/assets/js/commit.js';
-import {Drawer, BranchSelector, LimitSlider} from '/assets/js/drawer.js';
+import {Drawer, BranchSelector, LimitSlider, CommitRepresentation} from '/assets/js/drawer.js';
var _oneLine_ = true;
@@ -103,6 +103,7 @@
LimitSlider(() => {table.reload()}, 10000, 1000),
OneLineSwitch(),
BranchSelector(() => {table.reload()}),
+ CommitRepresentation(() => {table.reload()}),
])}
<div class="main right-sidebar under-topbar-with-actions">
<div class="content">${table}</div>
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/documentation.html (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/documentation.html 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/documentation.html 2021-03-16 22:09:55 UTC (rev 274523)
@@ -104,6 +104,18 @@
],
),
documentEndpoint(
+ '/api/commits/representations',
+ ['GET'],
+ [],
+ [
+ `Return a dictionary of prioritized valid commit representations for repositories tracked by this instance to the results database. The output is of the form:`,
+ codeBlock('{\n' +
+ ' <repository-id (a)>: ["hash", "identifier"],\n' +
+ ' <repository-id (b)>: ["identifier", "revision"]\n' +
+ '}'),
+ ],
+ ),
+ documentEndpoint(
'/api/commits/branches',
['GET'],
['Limit', 'Repository'],
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/search.html (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/search.html 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/search.html 2021-03-16 22:09:55 UTC (rev 274523)
@@ -1,5 +1,5 @@
<!--
- Copyright (C) 2019 Apple Inc. All rights reserved.
+ Copyright (C) 2019-2021 Apple Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -33,7 +33,7 @@
import {CommitBank} from '/assets/js/commit.js';
import {deepCompare, ErrorDisplay, queryToParams, paramsToQuery} from '/assets/js/common.js';
import {Configuration} from '/assets/js/configuration.js';
-import {Drawer, BranchSelector, ConfigurationSelectors, LimitSlider} from '/assets/js/drawer.js';
+import {Drawer, BranchSelector, ConfigurationSelectors, LimitSlider, CommitRepresentation} from '/assets/js/drawer.js';
import {InvestigateDrawer} from '/assets/js/investigate.js';
import {SearchBar} from '/assets/js/search.js';
import {Legend, TimelineFromEndpoint} from '/assets/js/timeline.js';
@@ -239,6 +239,7 @@
view.reload();
}),
ConfigurationSelectors(() => {view.reload()}),
+ CommitRepresentation(() => {view.reload()}),
], () => onLayoutChange.add())}
<div class="main right-sidebar under-topbar-with-actions">
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/suite_results.html (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/suite_results.html 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/templates/suite_results.html 2021-03-16 22:09:55 UTC (rev 274523)
@@ -1,5 +1,5 @@
<!--
- Copyright (C) 2019 Apple Inc. All rights reserved.
+ Copyright (C) 2019-2021 Apple Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -33,7 +33,7 @@
import {CommitBank} from '/assets/js/commit.js';
import {deepCompare, ErrorDisplay, queryToParams, paramsToQuery} from '/assets/js/common.js';
import {Configuration} from '/assets/js/configuration.js';
-import {Drawer, BranchSelector, ConfigurationSelectors, LimitSlider} from '/assets/js/drawer.js';
+import {Drawer, BranchSelector, ConfigurationSelectors, LimitSlider, CommitRepresentation} from '/assets/js/drawer.js';
import {InvestigateDrawer} from '/assets/js/investigate.js';
import {Legend, TimelineFromEndpoint} from '/assets/js/timeline.js';
import {ToolTip} from '/assets/js/tooltip.js';
@@ -182,6 +182,7 @@
view.reload();
}),
ConfigurationSelectors(() => {view.reload()}),
+ CommitRepresentation(() => {view.reload()}),
], () => onLayoutChange.add())}
<div class="main right-sidebar under-topbar-with-actions">
<br>
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/setup.py (274522 => 274523)
--- trunk/Tools/Scripts/libraries/resultsdbpy/setup.py 2021-03-16 21:58:54 UTC (rev 274522)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/setup.py 2021-03-16 22:09:55 UTC (rev 274523)
@@ -30,7 +30,7 @@
setup(
name='resultsdbpy',
- version='2.0.1',
+ version='2.0.2',
description='Library for visualizing, processing and storing test results.',
long_description=readme(),
classifiers=[