Merge "Give specific command in update change instruction"
This commit is contained in:
commit
9dd2fa2aaf
@ -608,6 +608,7 @@ limitations under the License.
|
||||
</gr-overlay>
|
||||
<gr-overlay id="uploadHelpOverlay" with-backdrop>
|
||||
<gr-upload-help-dialog
|
||||
revision="[[_currentRevision]]"
|
||||
target-branch="[[_change.branch]]"
|
||||
on-close="_handleCloseUploadHelpDialog"></gr-upload-help-dialog>
|
||||
</gr-overlay>
|
||||
|
@ -136,6 +136,11 @@
|
||||
},
|
||||
/** @type {?} */
|
||||
_commitInfo: Object,
|
||||
_currentRevision: {
|
||||
type: Object,
|
||||
computed: '_computeCurrentRevision(_change.current_revision, ' +
|
||||
'_change.revisions)',
|
||||
},
|
||||
_files: Object,
|
||||
_changeNum: String,
|
||||
_diffDrafts: {
|
||||
@ -1642,5 +1647,9 @@
|
||||
this.$.restAPI.saveChangeStarred(e.detail.change._number,
|
||||
e.detail.starred);
|
||||
},
|
||||
|
||||
_computeCurrentRevision(currentRevision, revisions) {
|
||||
return revisions && revisions[currentRevision];
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../shared/gr-dialog/gr-dialog.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
<link rel="import" href="../../shared/gr-shell-command/gr-shell-command.html">
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
|
||||
@ -47,9 +48,12 @@ limitations under the License.
|
||||
<ol>
|
||||
<li>
|
||||
<p>
|
||||
Checkout this change locally and make your desired modifications to
|
||||
the files.
|
||||
Checkout this change locally and make your desired modifications
|
||||
to the files.
|
||||
</p>
|
||||
<template is="dom-if" if="[[_fetchCommand]]">
|
||||
<gr-shell-command command="[[_fetchCommand]]"></gr-shell-command>
|
||||
</template>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
@ -71,6 +75,7 @@ limitations under the License.
|
||||
</ol>
|
||||
</div>
|
||||
</gr-dialog>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
</template>
|
||||
<script src="gr-upload-help-dialog.js"></script>
|
||||
</dom-module>
|
||||
|
@ -20,6 +20,13 @@
|
||||
const COMMIT_COMMAND = 'git add . && git commit --amend --no-edit';
|
||||
const PUSH_COMMAND_PREFIX = 'git push origin HEAD:refs/for/';
|
||||
|
||||
// Command names correspond to download plugin definitions.
|
||||
const PREFERRED_FETCH_COMMAND_ORDER = [
|
||||
'checkout',
|
||||
'cherry pick',
|
||||
'pull',
|
||||
];
|
||||
|
||||
Polymer({
|
||||
is: 'gr-upload-help-dialog',
|
||||
|
||||
@ -30,23 +37,83 @@
|
||||
*/
|
||||
|
||||
properties: {
|
||||
revision: Object,
|
||||
targetBranch: String,
|
||||
_commitCommand: {
|
||||
type: String,
|
||||
value: COMMIT_COMMAND,
|
||||
readOnly: true,
|
||||
},
|
||||
_fetchCommand: {
|
||||
type: String,
|
||||
computed: '_computeFetchCommand(revision, ' +
|
||||
'_preferredDownloadCommand, _preferredDownloadScheme)',
|
||||
},
|
||||
_preferredDownloadCommand: String,
|
||||
_preferredDownloadScheme: String,
|
||||
_pushCommand: {
|
||||
type: String,
|
||||
computed: '_computePushCommand(targetBranch)',
|
||||
},
|
||||
},
|
||||
|
||||
attached() {
|
||||
this.$.restAPI.getLoggedIn().then(loggedIn => {
|
||||
if (loggedIn) {
|
||||
return this.$.restAPI.getPreferences();
|
||||
}
|
||||
}).then(prefs => {
|
||||
if (prefs) {
|
||||
this._preferredDownloadCommand = prefs.download_command;
|
||||
this._preferredDownloadScheme = prefs.download_scheme;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_handleCloseTap(e) {
|
||||
e.preventDefault();
|
||||
this.fire('close', null, {bubbles: false});
|
||||
},
|
||||
|
||||
_computeFetchCommand(revision, preferredDownloadCommand,
|
||||
preferredDownloadScheme) {
|
||||
if (!revision) { return; }
|
||||
if (!revision || !revision.fetch) { return; }
|
||||
|
||||
let scheme = preferredDownloadScheme;
|
||||
if (!scheme) {
|
||||
const keys = Object.keys(revision.fetch).sort();
|
||||
if (keys.length === 0) {
|
||||
return;
|
||||
}
|
||||
scheme = keys[0];
|
||||
}
|
||||
|
||||
if (!revision.fetch[scheme] || !revision.fetch[scheme].commands) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cmds = {};
|
||||
Object.entries(revision.fetch[scheme].commands).forEach(([key, cmd]) => {
|
||||
cmds[key.toLowerCase()] = cmd;
|
||||
});
|
||||
|
||||
if (preferredDownloadCommand &&
|
||||
cmds[preferredDownloadCommand.toLowerCase()]) {
|
||||
return cmds[preferredDownloadCommand.toLowerCase()];
|
||||
}
|
||||
|
||||
// If no supported command preference is given, look for known commands
|
||||
// from the downloads plugin in order of preference.
|
||||
for (let i = 0; i < PREFERRED_FETCH_COMMAND_ORDER.length; i++) {
|
||||
if (cmds[PREFERRED_FETCH_COMMAND_ORDER[i]]) {
|
||||
return cmds[PREFERRED_FETCH_COMMAND_ORDER[i]];
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
|
||||
_computePushCommand(targetBranch) {
|
||||
return PUSH_COMMAND_PREFIX + targetBranch;
|
||||
},
|
||||
|
@ -48,5 +48,67 @@ limitations under the License.
|
||||
assert.equal(element._pushCommand,
|
||||
'git push origin HEAD:refs/for/master');
|
||||
});
|
||||
|
||||
suite('fetch command', () => {
|
||||
const testRev = {
|
||||
fetch: {
|
||||
http: {
|
||||
commands: {
|
||||
Checkout: 'http checkout',
|
||||
Pull: 'http pull',
|
||||
},
|
||||
},
|
||||
ssh: {
|
||||
commands: {
|
||||
Pull: 'ssh pull',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
test('null cases', () => {
|
||||
assert.isUndefined(element._computeFetchCommand());
|
||||
assert.isUndefined(element._computeFetchCommand({}));
|
||||
assert.isUndefined(element._computeFetchCommand({fetch: null}));
|
||||
assert.isUndefined(element._computeFetchCommand({fetch: {}}));
|
||||
});
|
||||
|
||||
test('insufficiently defined scheme', () => {
|
||||
assert.isUndefined(
|
||||
element._computeFetchCommand(testRev, undefined, 'badscheme'));
|
||||
|
||||
const rev = Object.assign({}, testRev);
|
||||
rev.fetch = Object.assign({}, testRev.fetch, {nocmds: {commands: {}}});
|
||||
assert.isUndefined(
|
||||
element._computeFetchCommand(rev, undefined, 'nocmds'));
|
||||
|
||||
rev.fetch.nocmds.commands.unsupported = 'unsupported';
|
||||
assert.isUndefined(
|
||||
element._computeFetchCommand(rev, undefined, 'nocmds'));
|
||||
});
|
||||
|
||||
test('default scheme and command', () => {
|
||||
const cmd = element._computeFetchCommand(testRev);
|
||||
assert.isTrue(cmd === 'http checkout' || cmd === 'ssh pull');
|
||||
});
|
||||
|
||||
test('default command', () => {
|
||||
assert.strictEqual(
|
||||
element._computeFetchCommand(testRev, undefined, 'http'),
|
||||
'http checkout');
|
||||
assert.strictEqual(
|
||||
element._computeFetchCommand(testRev, undefined, 'ssh'),
|
||||
'ssh pull');
|
||||
});
|
||||
|
||||
test('user preferred scheme and command', () => {
|
||||
assert.strictEqual(
|
||||
element._computeFetchCommand(testRev, 'PULL', 'http'),
|
||||
'http pull');
|
||||
assert.strictEqual(
|
||||
element._computeFetchCommand(testRev, 'badcmd', 'http'),
|
||||
'http checkout');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user