diff --git a/scripts/release-info.js b/scripts/release-info.js index 83c58c94..fb320da0 100644 --- a/scripts/release-info.js +++ b/scripts/release-info.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@auto-it/core"); + /** * Auto plugin that posts a PR comment with version information when a release is created */ @@ -11,6 +12,7 @@ class ReleaseInfo { this.context = options.context || "Release Info"; this.notes = options.notes || {}; } + /** * Get the appropriate message based on the release context * @param version The version string @@ -20,6 +22,7 @@ class ReleaseInfo { getVersionMessage(version, releaseContext) { const currentDate = new Date().toUTCString(); let versionMessage = `### ${this.context}\n\n`; + // Customize message based on release context switch (releaseContext) { case "canary": @@ -35,42 +38,55 @@ class ReleaseInfo { versionMessage += `A new version was released on \`${currentDate}\`:\n\n`; break; } + versionMessage += "```\n"; versionMessage += `${version}\n`; versionMessage += "```"; + // Add the context-specific note if provided const note = this.notes[releaseContext] || this.notes.default; if (note) { versionMessage += "\n\n"; versionMessage += note; } + return versionMessage; } + /** Apply the plugin to the Auto instance */ apply(auto) { // Handle all releases through afterShipIt hook auto.hooks.afterShipIt.tap(this.name, async (release) => { const { newVersion, context: releaseContext } = release; + if (!newVersion) { auto.logger.verbose.info( "No release version produced, skipping comment", ); return; } + auto.logger.verbose.info( `Processing ${releaseContext} release with version ${newVersion}`, ); + // Get the appropriate message for this release context const message = this.getVersionMessage(newVersion, releaseContext); + // Check if we're in a PR context before attempting to comment const prNumber = (0, core_1.getPrNumberFromEnv)(); + if (!prNumber) { - auto.logger.verbose.info( - "Auto shipit was triggered outside of a PR context, skipping comment", - ); + auto.logger.verbose.info("Not in PR context, skipping comment"); + return; + } + + if (!auto.comment) { + auto.logger.verbose.info("Auto comment not available, skipping"); return; } - // We have auto.comment, so we're in a PR context + + // Try to post comment try { await auto.comment({ message, @@ -78,14 +94,16 @@ class ReleaseInfo { }); auto.logger.verbose.info("Successfully posted version comment"); } catch (error) { - auto.logger.verbose.info("Error posting comment to PR:"); + auto.logger.verbose.info("Comment posting failed, continuing build"); if (error instanceof Error) { auto.logger.verbose.info(error.message); - } else { - auto.logger.verbose.info(String(error)); } } }); } } + +// Export in multiple formats for compatibility with different module loaders exports.default = ReleaseInfo; +module.exports = ReleaseInfo; +module.exports.default = ReleaseInfo;