Skip to content

Commit 6962cd8

Browse files
committed
Properly handle an new version being posted which is not the latest version.
1 parent 3ce0e97 commit 6962cd8

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

scripts/wordpress-update.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,30 @@ actions.addRelease = function( data, fn ) {
120120
this.parallel()( null, pageDetails );
121121
var versions = getVersions( existingPage ),
122122
mainPageCallback = this.parallel(),
123-
existingCustomFields = existingPage && existingPage.customFields ?
124-
existingPage.customFields : [],
123+
existingCustomFields = existingPage.customFields || [],
124+
mainPage = {
125+
customFields: existingCustomFields
126+
};
127+
128+
// The main page starts as an empty object so that publishing a new
129+
// version which is not the latest version only updates the metadata
130+
// of the main page. If the new version is the latest, then use the
131+
// main page is constructed from the new version since pretty much
132+
// anything can change between versions.
133+
if ( versions.latest === manifest.version ) {
125134
mainPage = Object.create( pageDetails );
135+
mainPage.name = manifest.name;
136+
mainPage.customFields = mergeCustomFields(
137+
existingCustomFields, pageDetails.customFields );
138+
}
126139

127-
mainPage.name = manifest.name;
128-
mainPage.customFields = mainPage.customFields.concat([
140+
// Always update the metadata for the main page
141+
mainPage.customFields = mergeCustomFields( mainPage.customFields, [
129142
{ key: "versions", value: JSON.stringify( versions.listed ) },
130143
{ key: "latest", value: versions.latest },
131144
{ key: "watchers", value: repoMeta.watchers },
132145
{ key: "forks", value: repoMeta.forks }
133146
]);
134-
mainPage.customFields = mergeCustomFields( existingCustomFields, mainPage.customFields );
135147

136148
if ( !existingPage.id ) {
137149
wordpress.newPost( mainPage, mainPageCallback );

0 commit comments

Comments
 (0)