Skip to content

Commit 58dfb88

Browse files
Copilotfgreinacher
andcommitted
Address review feedback: remove variables, comment, and use ternary operators
Co-authored-by: fgreinacher <[email protected]>
1 parent 91ffe12 commit 58dfb88

File tree

1 file changed

+23
-44
lines changed

1 file changed

+23
-44
lines changed

lib/publish.js

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,20 @@ export default async (pluginConfig, context) => {
5656
debug("milestones: %o", milestones);
5757

5858
if (assets && assets.length > 0) {
59-
// Apply template expansion to assets BEFORE globbing (original approach but moved before)
6059
const templatedAssets = assets.map((asset) => {
6160
if (isPlainObject(asset)) {
6261
const templatedAsset = { ...asset };
6362
if (asset.path) {
64-
if (Array.isArray(asset.path)) {
65-
templatedAsset.path = asset.path.map(pattern => template(pattern)(context));
66-
} else {
67-
templatedAsset.path = template(asset.path)(context);
68-
}
69-
}
70-
if (asset.url) {
71-
templatedAsset.url = template(asset.url)(context);
72-
}
73-
if (asset.label) {
74-
templatedAsset.label = template(asset.label)(context);
75-
}
76-
if (asset.type) {
77-
templatedAsset.type = template(asset.type)(context);
78-
}
79-
if (asset.filepath) {
80-
templatedAsset.filepath = template(asset.filepath)(context);
81-
}
82-
if (asset.target) {
83-
templatedAsset.target = template(asset.target)(context);
84-
}
85-
if (asset.status) {
86-
templatedAsset.status = template(asset.status)(context);
63+
templatedAsset.path = Array.isArray(asset.path)
64+
? asset.path.map(pattern => template(pattern)(context))
65+
: template(asset.path)(context);
8766
}
67+
templatedAsset.url = asset.url ? template(asset.url)(context) : asset.url;
68+
templatedAsset.label = asset.label ? template(asset.label)(context) : asset.label;
69+
templatedAsset.type = asset.type ? template(asset.type)(context) : asset.type;
70+
templatedAsset.filepath = asset.filepath ? template(asset.filepath)(context) : asset.filepath;
71+
templatedAsset.target = asset.target ? template(asset.target)(context) : asset.target;
72+
templatedAsset.status = asset.status ? template(asset.status)(context) : asset.status;
8873
return templatedAsset;
8974
} else if (Array.isArray(asset)) {
9075
// Handle array of glob patterns
@@ -109,16 +94,10 @@ export default async (pluginConfig, context) => {
10994
await Promise.all(
11095
allAssets.map(async (asset) => {
11196
const path = isPlainObject(asset) ? asset.path : asset;
112-
const _url = asset.url;
113-
const label = asset.label;
114-
const type = asset.type;
115-
const filepath = asset.filepath;
116-
const target = asset.target;
117-
const status = asset.status;
118-
119-
if (_url) {
120-
assetsList.push({ label, rawUrl: _url, type, filepath });
121-
debug("use link from release setting: %s", _url);
97+
98+
if (asset.url) {
99+
assetsList.push({ label: asset.label, rawUrl: asset.url, type: asset.type, filepath: asset.filepath });
100+
debug("use link from release setting: %s", asset.url);
122101
} else {
123102
const file = pathlib.resolve(cwd, path);
124103

@@ -137,24 +116,24 @@ export default async (pluginConfig, context) => {
137116
}
138117

139118
debug("file path: %o", path);
140-
debug("file label: %o", label);
141-
debug("file type: %o", type);
142-
debug("file filepath: %o", filepath);
143-
debug("file target: %o", target);
144-
debug("file status: %o", status);
119+
debug("file label: %o", asset.label);
120+
debug("file type: %o", asset.type);
121+
debug("file filepath: %o", asset.filepath);
122+
debug("file target: %o", asset.target);
123+
debug("file status: %o", asset.status);
145124

146125
let uploadEndpoint;
147126
let response;
148127

149-
if (target === "generic_package") {
150-
const finalLabel = label ?? pathlib.basename(file);
128+
if (asset.target === "generic_package") {
129+
const finalLabel = asset.label ?? pathlib.basename(file);
151130
// Upload generic packages
152131
const encodedLabel = encodeURIComponent(finalLabel);
153132
// https://docs.gitlab.com/ee/user/packages/generic_packages/#publish-a-package-file
154133
uploadEndpoint = urlJoin(
155134
projectApiUrl,
156135
`packages/generic/release/${encodedVersion}/${encodedLabel}?${
157-
status ? `status=${status}&` : ""
136+
asset.status ? `status=${asset.status}&` : ""
158137
}select=package_file`
159138
);
160139

@@ -170,7 +149,7 @@ export default async (pluginConfig, context) => {
170149
// https://docs.gitlab.com/ee/user/packages/generic_packages/#download-package-file
171150
const url = urlJoin(projectApiUrl, `packages/generic/release/${encodedVersion}/${encodedLabel}`);
172151

173-
assetsList.push({ label: finalLabel, alt: "release", url, type: "package", filepath });
152+
assetsList.push({ label: finalLabel, alt: "release", url, type: "package", filepath: asset.filepath });
174153

175154
logger.log("Uploaded file: %s (%s)", url, response.file.url);
176155
} else {
@@ -191,7 +170,7 @@ export default async (pluginConfig, context) => {
191170
const { alt, full_path } = response;
192171
const url = urlJoin(gitlabUrl, full_path);
193172

194-
assetsList.push({ label, alt, url, type, filepath });
173+
assetsList.push({ label: asset.label, alt, url, type: asset.type, filepath: asset.filepath });
195174

196175
logger.log("Uploaded file: %s", url);
197176
}

0 commit comments

Comments
 (0)