Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Bug 1146853 - submit_release: Populate the latest changeset automatic…
Browse files Browse the repository at this point in the history
…ally (#132)

* Fetch the latest changeset from hg.mozilla.org
* Elmo: Show download message as placeholder
* Remove Relbranch field from Firefox form
* Fix discrepency between versionElement.select() and versionElement.change(). This fixes a bug where l10n changesets weren't automatically fetched
  • Loading branch information
JohanLorenzo committed Jan 18, 2017
1 parent ebe86bc commit c6122a6
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 51 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Expand Up @@ -3,8 +3,9 @@ sources = [
"kickoff/static/kickoff.js",
"kickoff/static/model/release.js",
"kickoff/static/model/errors.js",
"kickoff/static/suggestions.js",
"kickoff/static/treestatus.js",
"kickoff/static/hg_mozilla.js",
"kickoff/static/suggestions.js",
];

module.exports = function(grunt) {
Expand Down
1 change: 1 addition & 0 deletions kickoff/static/global_config.js
Expand Up @@ -2,6 +2,7 @@ var CONFIG = {
baseUrls: {
elmo: 'https://l10n.mozilla.org/shipping/',
treestatus: 'https://treestatus.mozilla.org/',
hgMozilla: 'https://hg.mozilla.org/',
},
};

Expand Down
33 changes: 33 additions & 0 deletions kickoff/static/hg_mozilla.js
@@ -0,0 +1,33 @@
function getJsonPushesUrl(branchName) {
return CONFIG.baseUrls.hgMozilla + branchName + '/json-pushes';
}

function pluckLatestRevision(jsonPushes) {
var pushIds = Object.keys(jsonPushes);
pushIds = pushIds.map(function(pushId) { return parseInt(pushId); });
latestPushId = pushIds.reduce(function(latest, challenger) { return challenger > latest ? challenger : latest; });
latestRevisions = jsonPushes[latestPushId].changesets;
return latestRevisions[latestRevisions.length - 1];
}

function populateRevisionWithLatest(productName, branchName) {
var revisionElement = $('#' + productName + '-mozillaRevision');
var oldPlaceholder = revisionElement.attr('placeholder');

revisionElement.attr('placeholder', 'Fetching latest revision');
revisionElement.prop('disabled', true);

$.ajax({
url: getJsonPushesUrl(branchName),
}).done(function(results) {
var latestRevision = pluckLatestRevision(results);
revisionElement.val(latestRevision);
}).fail(function() {
revisionElement.val('');
console.error('Could not fetch latest revision for branch "' + branchName + '"');
}).always(function() {
revisionElement.prop('disabled', false);
revisionElement.attr('placeholder', oldPlaceholder);
revisionElement.blur(); // this deactivates relbranch field, if needed
});
}
66 changes: 36 additions & 30 deletions kickoff/static/suggestions.js
Expand Up @@ -131,6 +131,10 @@ function stripBuildNumber(release) {
}

function populatePartial(productName, version, previousBuilds, partialElement) {
if (isFennec(productName)) {
// Fennec doesn't support partials
return;
}

partialElement.val('');

Expand Down Expand Up @@ -273,7 +277,7 @@ function getPreviousBuildL10nUrl(productName, version, previousBuildNumber) {
function getUrlAndMessages(productName, version, buildNumber) {
var opts = {
url: '',
downloadMessage: 'Trying to download from ',
downloadPlaceholder: 'Trying to download from ',
previousBuildWarning: '',
};
var minor = version.match(/(\d+)\.\d+\.\d+/);
Expand All @@ -283,19 +287,19 @@ function getUrlAndMessages(productName, version, buildNumber) {
var previousVersion = minor[1] + '.0';
var buildString = previousVersion + ' build' + previousBuildNumber;
opts.url = getPreviousBuildL10nUrl(productName, previousVersion, previousBuildNumber);
opts.downloadMessage += buildString;
opts.downloadPlaceholder += buildString;
opts.previousBuildWarning = 'Changesets copied from ' + buildString +
'. If you want to not use them, please edit this field.';
} else if (buildNumber > 1) {
var previousBuildNumber = buildNumber - 1;
var buildString = 'build' + previousBuildNumber;
opts.url = getPreviousBuildL10nUrl(productName, version, previousBuildNumber);
opts.downloadMessage += buildString;
opts.downloadPlaceholder += buildString;
opts.previousBuildWarning = 'Changesets copied from ' + buildString +
'. If you want to not use them, please edit this field.';
} else {
opts.url = getElmoUrl(productName, version);
opts.downloadMessage += 'Elmo';
opts.downloadPlaceholder += 'Elmo';
opts.previousBuildWarning = '';
}

Expand All @@ -310,10 +314,12 @@ function populateL10nChangesets(productName, version, buildNumber) {
return;
}

var oldPlaceholder = changesetsElement.attr('placeholder');
var warningElement = changesetsElement.siblings('.help').find('.warning');
var opts = getUrlAndMessages(productName, version, buildNumber);

changesetsElement.val(opts.downloadMessage);
changesetsElement.val('');
changesetsElement.attr('placeholder', opts.downloadPlaceholder);
changesetsElement.prop('disabled', true);
warningElement.text('');

Expand All @@ -328,6 +334,7 @@ function populateL10nChangesets(productName, version, buildNumber) {
console.error('Could not fetch l10n changesets');
}).always(function() {
changesetsElement.prop('disabled', false);
changesetsElement.attr('placeholder', oldPlaceholder);
warningElement.text(opts.previousBuildWarning);
});
}
Expand Down Expand Up @@ -357,9 +364,15 @@ function setupVersionSuggestions(versionElement, versions, buildNumberElement, b
var branch = guessBranchFromVersion(productName, version);
branchElement.val(branch);
branchElement.trigger('change');
return branch;
}

function populatePartialInfo(version) {
function populatePartialInfo(productName, version) {
if (isFennec(productName)) {
// Fennec doesn't support partials
return;
}

if (partialsADI.length == 0 || !isRelease(version)) {
partialInfo.html('');
// No ADI available, don't display anything
Expand All @@ -375,6 +388,20 @@ function setupVersionSuggestions(versionElement, versions, buildNumberElement, b
partialInfo.html(partialString);
}

function populateAllPossibleFields(productName, rawVersion, buildNumberElement, previousBuilds, partialElement) {
// TODO show a warning if version is not correct
var version = getSanitizedVersionString(rawVersion);

populateBuildNumber(version);
var buildNumber = buildNumberElement.val();
var branchName = populateBranch(productName, version);

populateRevisionWithLatest(productName, branchName);
populatePartial(productName, version, previousBuilds, partialElement);
populatePartialInfo(productName, version);
populateL10nChangesets(productName, version, buildNumber);
}

var VERSION_SUFFIX = '-version';
versionElement.autocomplete({
source: versions,
Expand All @@ -389,35 +416,14 @@ function setupVersionSuggestions(versionElement, versions, buildNumberElement, b
collision: 'flipfit',
},
select: function(event, ui) {
var fieldName = event.target.name;
// TODO show a warning if version is not correct
var version = getSanitizedVersionString(ui.item.value);
var productName = fieldName.slice(0, -VERSION_SUFFIX.length);

populateBuildNumber(version);
var buildNumber = buildNumberElement.val();

populateBranch(productName, version);
if (!isFennec(productName)) {
// There is no notion of partial on fennec
populatePartial(productName, version, previousBuilds, partialElement);
populatePartialInfo(version);
}
populateL10nChangesets(productName, version, buildNumber);
var productName = event.target.name.slice(0, -VERSION_SUFFIX.length);
populateAllPossibleFields(productName, ui.item.value, buildNumberElement, previousBuilds, partialElement);
}
}).focus(function() {
$(this).autocomplete('search');
}).change(function() {
var productName = this.name.slice(0, -VERSION_SUFFIX.length);
// TODO show a warning if version is not correct
var version = getSanitizedVersionString(this.value);

populateBuildNumber(version);
var buildNumber = buildNumberElement.val();

populateBranch(productName, version);
populatePartial(productName, version, previousBuilds, partialElement);
populateL10nChangesets(productName, version, buildNumber);
populateAllPossibleFields(productName, this.value, buildNumberElement, previousBuilds, partialElement);
});
}

Expand Down
1 change: 1 addition & 0 deletions kickoff/templates/base.html
Expand Up @@ -8,6 +8,7 @@
<script type='text/javascript' src="{{ url_for("static", filename="global_config.js") }}"></script>
<script type='text/javascript' src="{{ url_for("static", filename="model/errors.js") }}"></script>
<script type='text/javascript' src="{{ url_for("static", filename="model/release.js") }}"></script>
<script type='text/javascript' src="{{ url_for("static", filename="hg_mozilla.js") }}"></script>
<script type='text/javascript' src="{{ url_for("static", filename="suggestions.js") }}"></script>
<script type='text/javascript' src="{{ url_for("static", filename="jquery-ui-1.10.2.custom.min.js") }}"></script>
<script type='text/javascript' src="{{ url_for("static", filename="jquery-1.9.1.min.js") }}"></script>
Expand Down
21 changes: 2 additions & 19 deletions kickoff/templates/includes/firefox_release.html
Expand Up @@ -27,10 +27,6 @@
$('#{{ firefoxForm.partials.id }}'),
{{ firefoxForm.partials.suggestions|safe }}
);
setupRevisionDisabling(
$('#{{ firefoxForm.mozillaRelbranch.id }}'),
$('#{{ firefoxForm.mozillaRevision.id }}')
);
})
</script>
{{ firefoxForm.hidden_tag() }}
Expand All @@ -54,12 +50,8 @@
</div>
<div class="submit_release">
{{ firefoxForm.mozillaRevision.label()|safe }}
{% if firefoxForm.mozillaRelbranch.data %}
{{ firefoxForm.mozillaRevision(disabled='disabled')|safe }}
{% else %}
{{ firefoxForm.mozillaRevision(placeholder='abcdef123456')|safe }}
{% endif %}
<div class="help">If a relbranch is specified this field is disabled and ignored. The tip of the relbranch will be used instead. It is strongly recommended to select a changeset which has been fully built/tested on the TBPL tool (examples: <a href="https://tbpl.mozilla.org/?tree=Mozilla-Beta">Beta</a> or <a href="https://tbpl.mozilla.org/?tree=Mozilla-Release">Release</a>)</div>
{{ firefoxForm.mozillaRevision(placeholder='abcdef123456')|safe }}
<div class="help">It is strongly recommended to select a changeset which has been fully built/tested on the TBPL tool (examples: <a href="https://tbpl.mozilla.org/?tree=Mozilla-Beta">Beta</a> or <a href="https://tbpl.mozilla.org/?tree=Mozilla-Release">Release</a>)</div>
</div>
<div class="submit_release">
{{ firefoxForm.partials.label()|safe }}
Expand All @@ -77,15 +69,6 @@ <h4>Advanced Options:</h4>
The l10n changesets for this release (first column: locale, second: revision). Betas and release-channel releases these are normally copied from the <a href="https://l10n.mozilla.org/shipping/milestones">L10n Dashboard</a>. ESR releases re-use the same changesets as the previous release on the same branch. For more information consult <a href="https://wiki.mozilla.org/Release:Release_Automation_on_Mercurial:Starting_a_Release#L10N_Changesets">the milestone creation documentation</a>
</div>
</div>
<div class="submit_release">
{{ firefoxForm.mozillaRelbranch.label()|safe }}
{% if firefoxForm.mozillaRevision.data %}
{{ firefoxForm.mozillaRelbranch(disabled='disabled')|safe }}
{% else %}
{{ firefoxForm.mozillaRelbranch()|safe }}
{% endif %}
<div class="help">If a revision is specified this field is disabled and ignored otherwise the relbranch specified will be used put version bumps/tags for this release on. If not specified, one will be generated automatically during tagging. When provided the release will be created from tip of this branch thus it cannot be used in conjunction with revision.</div>
</div>
<div class="submit_release">
{{ firefoxForm.promptWaitTime.label()|safe }}
{{ firefoxForm.promptWaitTime()|safe }}
Expand Down
3 changes: 2 additions & 1 deletion kickoff/test/js/jstest.html
Expand Up @@ -14,8 +14,9 @@
<script src="../../static/global_config.js"></script>
<script src="../../static/model/errors.js"></script>
<script src="../../static/model/release.js"></script>
<script src="../../static/suggestions.js"></script>
<script src="../../static/treestatus.js"></script>
<script src="../../static/hg_mozilla.js"></script>
<script src="../../static/suggestions.js"></script>
<script src="tests.js"></script>
</body>
</html>
46 changes: 46 additions & 0 deletions kickoff/test/js/tests.js
Expand Up @@ -346,6 +346,52 @@ QUnit.test('getTreeStatusUrl()', function(assert) {
});


QUnit.test('getJsonPushesUrl()', function(assert) {
var data = [{
branch: 'releases/mozilla-release',
expectedUrl: 'https://hg.mozilla.org/releases/mozilla-release/json-pushes',
}, {
branch: 'releases/mozilla-beta',
expectedUrl: 'https://hg.mozilla.org/releases/mozilla-beta/json-pushes',
}, {
branch: 'releases/comm-beta',
expectedUrl: 'https://hg.mozilla.org/releases/comm-beta/json-pushes',
}, {
branch: 'releases/comm-esr45',
expectedUrl: 'https://hg.mozilla.org/releases/comm-esr45/json-pushes',
}];

data.forEach(function(piece) {
assert.equal(
getJsonPushesUrl(piece.branch),
piece.expectedUrl
);
});
});

QUnit.test('pluckLatestRevision()', function(assert) {
jsonPush = {
"6527": {
"changesets": ["00f11e7650b184162dbedf9c82a7917b5c07d216", "1ad4ab26875c6512b577f8f6974260fcd76d35b6", "79247eb8ce1f6c5e4444c196983cf7630fa62e9c", "d69e6eb5d19f81e22ddd026857e2b5b7b57d37b5"],
"date": 1477014593,
"user": "r@g.c"
},
"6528": {
"changesets": ["328aacd63a389e49956cc34b3be052ffd5f5b519", "0f6ce21169761fde4d0d9058984b1ba3c651e6b5"],
"date": 1477082000,
"user": "ffxbld"
},
"6529": {
"changesets": ["41f4ad2acadfef63851abed019bad9b91923b8fc", "f8422ce3d9c6743ef467c1e3394fb83762298a8c", "29a171c7f26dcff9326ffd950e5446ee1f9d0d7b", "fac7c4b729ccd735faa0c4434ae7eede3be95dd6"],
"date": 1477246215,
"user": "r@g.c"
}
};

assert.equal(pluckLatestRevision(jsonPush), 'fac7c4b729ccd735faa0c4434ae7eede3be95dd6');
});


QUnit.module('model/Release');

QUnit.test('constructor must throw errors when release has more than one type', function(assert) {
Expand Down

0 comments on commit c6122a6

Please sign in to comment.