@tarsilla/commit-wizard 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"crypto";import t from"fs";import{
|
|
1
|
+
import e from"crypto";import t from"fs";import{Octokit as a}from"@octokit/rest";import{analyzeCommits as r}from"@semantic-release/commit-analyzer";import{prepare as s,verifyConditions as o}from"@semantic-release/git";import{generateNotes as n}from"@semantic-release/release-notes-generator";const i={preset:"conventionalcommits",parserOpts:{headerPattern:RegExp("^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$"),headerCorrespondence:["type","exclamation1","scope","exclamation2","subject"]},releaseRules:[{type:"feat",exclamation1:"!",release:"major"},{type:"feat",exclamation2:"!",release:"major"},{type:"feat",release:"minor"},{type:"fix",release:"patch"},{type:"docs",release:"patch"},{type:"style",release:"patch"},{type:"refactor",release:"patch"},{type:"perf",release:"patch"},{type:"test",release:"patch"},{type:"build",release:"patch"},{type:"ci",release:"patch"},{type:"chore",release:"patch"},{type:"revert",release:"patch"}]};let c=!1;function l(e,t){const a=new URL(t).pathname,r=(a.startsWith("/")?a.slice(1):a).split("/").pop();return e.tap??`${r}.rb`}async function p(a,r){const{nextRelease:s,logger:o,options:n}=r;if(!s?.version)throw new Error("Next release version is not available.");const i=`v${s.version}`,c=n.repositoryUrl,p=new URL(c).pathname,m=`https://codeload.github.com/${p.startsWith("/")?p.slice(1):p}/tar.gz/refs/tags/${i}`,f=await async function(t,a){const{logger:r}=a;r.log(`Calculating SHA256 for URL: ${t}`);const s=await fetch(t);if(!s.ok)throw new Error(`Failed to fetch file. Status Code: ${s.status}`);if(!s.body)throw new Error("Response body is null.");const o=e.createHash("sha256"),n=s.body.getReader();return new Promise(((e,t)=>{!function a(){n.read().then((({done:t,value:r})=>{t?e(o.digest("hex")):(r&&o.update(r),a())})).catch(t)}()}))}(m,r),h=l(a,c);let y=t.readFileSync(h,"utf8");y=y.replace(/url ".*"/,`url "${m}"`),y=y.replace(/sha256 ".*"/,`sha256 "${f}"`),t.writeFileSync(h,y),o.log(`Updated formula with version ${i}, URL ${m}, and SHA256 ${f}`)}async function m(e,t){if(o){const{options:a}=t,r=l(e,a.repositoryUrl);await o({assets:[r],message:"chore(release): ${nextRelease.version}"},t)}c=!0}const f={addChannel:async function(e,t){},verifyConditions:m,analyzeCommits:async function(e,t){return c||(await m(e,t),c=!0),r(i,t)},generateNotes:async function(e,t){return c||(await m(e,t),c=!0),n({},t)},prepare:async function(e,t){if(c||(await m(e,t),c=!0),s){const{options:r}=t,o=l(e,r.repositoryUrl);await async function(e,t){if(!process.env.GITHUB_TOKEN)throw new Error("GITHUB_TOKEN is not set in the environment.");const{nextRelease:r,logger:s,options:o}=t,n=`v${r.version}`,i=o.repositoryUrl,[c,l]=new URL(i).pathname.slice(1).split("/");s.log(`Creating tag ${n} using GitHub API...`);const p=new a({auth:process.env.GITHUB_TOKEN});try{const e=o.branch??"main";s.log(`Branch name: ${e}`);const{data:t}=await p.repos.getBranch({owner:c,repo:l,branch:e}),a=t.commit.sha;s.log(`Latest commit SHA: ${a}`),s.log(`Creating tag object for ${n}...`),await p.git.createTag({owner:c,repo:l,tag:n,message:`Release ${n}`,object:a,type:"commit"}),s.log(`Creating reference for tag ${n}...`),await p.git.createRef({owner:c,repo:l,ref:`refs/tags/${n}`,sha:a}),s.log(`Tag ${n} created successfully.`)}catch(e){throw s.error(`Failed to create tag ${n}: ${e.message}`),e}}(0,t),await p(e,t),await s({assets:[o],message:"chore(release): ${nextRelease.version}"},t)}},publish:async function(e,t){return null},success:async function(e,t){},fail:async function(e,t){}};export{f as default};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/semantic-release/brew/index.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\n\n//@ts-ignore\nimport { analyzeCommits as commitAnalyzerAnalyzeCommits } from '@semantic-release/commit-analyzer';\nimport {\n prepare as gitPrepare,\n verifyConditions as gitVerifyConditions,\n //@ts-ignore\n} from '@semantic-release/git';\n//@ts-ignore\nimport { generateNotes as notesGeneratorGenerateNotes } from '@semantic-release/release-notes-generator';\nimport {\n AddChannelContext,\n AnalyzeCommitsContext,\n FailContext,\n GenerateNotesContext,\n PrepareContext,\n PublishContext,\n SuccessContext,\n VerifyConditionsContext,\n} from 'semantic-release';\n\nimport { SemanticReleasePlugin } from '../types.js';\n\nconst analyzerConfig = {\n preset: 'conventionalcommits',\n parserOpts: {\n headerPattern: /^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$/,\n headerCorrespondence: ['type', 'exclamation1', 'scope', 'exclamation2', 'subject'],\n },\n releaseRules: [\n { type: 'feat', exclamation1: '!', release: 'major' },\n { type: 'feat', exclamation2: '!', release: 'major' },\n { type: 'feat', release: 'minor' },\n { type: 'fix', release: 'patch' },\n { type: 'docs', release: 'patch' },\n { type: 'style', release: 'patch' },\n { type: 'refactor', release: 'patch' },\n { type: 'perf', release: 'patch' },\n { type: 'test', release: 'patch' },\n { type: 'build', release: 'patch' },\n { type: 'ci', release: 'patch' },\n { type: 'chore', release: 'patch' },\n { type: 'revert', release: 'patch' },\n ],\n};\n\ntype PluginConfig = { tap?: string };\n\nlet verified = false;\n\nasync function calculateSha256(url: string, context: PrepareContext): Promise<string> {\n const { logger } = context;\n\n logger.log(`Calculating SHA256 for URL: ${url}`);\n\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch file. Status Code: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error('Response body is null.');\n }\n\n const hash = crypto.createHash('sha256');\n const reader = response.body.getReader();\n\n return new Promise((resolve, reject) => {\n function read() {\n reader\n .read()\n .then(({ done, value }) => {\n if (done) {\n resolve(hash.digest('hex'));\n return;\n }\n if (value) {\n hash.update(value);\n }\n read();\n })\n .catch(reject);\n }\n read();\n });\n}\n\nfunction getFormulaFile(pluginConfig: PluginConfig, repositoryUrl: string): string {\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n const project = repository.split('/').pop();\n\n return pluginConfig.tap ?? `${project}.rb`;\n}\n\nasync function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n const { nextRelease, logger, options } = context;\n\n if (!nextRelease?.version) {\n throw new Error('Next release version is not available.');\n }\n\n const version = nextRelease.version;\n\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n\n const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/v${version}`;\n const sha256 = await calculateSha256(tarUrl, context);\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n\n let formulaContent = fs.readFileSync(formulaFile, 'utf8');\n formulaContent = formulaContent.replace(/url \".*\"/, `url \"${tarUrl}\"`);\n formulaContent = formulaContent.replace(/sha256 \".*\"/, `sha256 \"${sha256}\"`);\n fs.writeFileSync(formulaFile, formulaContent);\n\n logger.log(`Updated formula with version ${version}, URL ${tarUrl}, and SHA256 ${sha256}`);\n}\n\nasync function addChannel(_pluginConfig: PluginConfig, _context: AddChannelContext): Promise<void> {\n //do nothing\n}\n\nasync function analyzeCommits(pluginConfig: PluginConfig, context: AnalyzeCommitsContext): Promise<string | false> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return commitAnalyzerAnalyzeCommits(analyzerConfig, context);\n}\n\nasync function fail(_pluginConfig: PluginConfig, _context: FailContext): Promise<void> {\n //do nothing\n}\n\nasync function generateNotes(pluginConfig: PluginConfig, context: GenerateNotesContext): Promise<string> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return notesGeneratorGenerateNotes({}, context);\n}\n\nasync function prepare(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n if (gitPrepare) {\n const { options } = context;\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n\n await updateFormulaFile(pluginConfig, context);\n\n await gitPrepare(\n {\n assets: [formulaFile],\n message: 'chore(release): ${nextRelease.version}',\n },\n context,\n );\n }\n}\n\nasync function publish(_pluginConfig: PluginConfig, _context: PublishContext): Promise<unknown> {\n //do nothing\n return null;\n}\n\nasync function success(_pluginConfig: PluginConfig, _context: SuccessContext): Promise<void> {\n //do nothing\n}\n\nasync function verifyConditions(pluginConfig: PluginConfig, context: VerifyConditionsContext): Promise<void> {\n if (gitVerifyConditions) {\n const { options } = context;\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n await gitVerifyConditions(\n {\n assets: [formulaFile],\n message: 'chore(release): ${nextRelease.version}',\n },\n context,\n );\n }\n verified = true;\n}\n\nconst plugin: SemanticReleasePlugin<{ tap: string }> = {\n addChannel,\n verifyConditions,\n analyzeCommits,\n generateNotes,\n prepare,\n publish,\n success,\n fail,\n};\n\nexport default plugin;\n"],"names":["analyzerConfig","preset","parserOpts","headerPattern","RegExp","headerCorrespondence","releaseRules","type","exclamation1","release","exclamation2","verified","getFormulaFile","pluginConfig","repositoryUrl","repositoryPath","URL","pathname","project","startsWith","slice","split","pop","tap","async","updateFormulaFile","context","nextRelease","logger","options","version","Error","tarUrl","sha256","url","log","response","fetch","ok","status","body","hash","crypto","createHash","reader","getReader","Promise","resolve","reject","read","then","done","value","digest","update","catch","calculateSha256","formulaFile","formulaContent","fs","readFileSync","replace","writeFileSync","verifyConditions","gitVerifyConditions","assets","message","plugin","addChannel","_pluginConfig","_context","analyzeCommits","commitAnalyzerAnalyzeCommits","generateNotes","notesGeneratorGenerateNotes","prepare","gitPrepare","publish","success","fail"],"mappings":"2PAyBA,MAAMA,EAAiB,CACrBC,OAAQ,sBACRC,WAAY,CACVC,cAAeC,OAAA,mGACfC,qBAAsB,CAAC,OAAQ,eAAgB,QAAS,eAAgB,YAE1EC,aAAc,CACZ,CAAEC,KAAM,OAAQC,aAAc,IAAKC,QAAS,SAC5C,CAAEF,KAAM,OAAQG,aAAc,IAAKD,QAAS,SAC5C,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,MAAOE,QAAS,SACxB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,WAAYE,QAAS,SAC7B,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,KAAME,QAAS,SACvB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,SAAUE,QAAS,WAM/B,IAAIE,GAAW,EAwCf,SAASC,EAAeC,EAA4BC,GAClD,MACMC,EADM,IAAIC,IAAIF,GACOG,SAErBC,GADaH,EAAeI,WAAW,KAAOJ,EAAeK,MAAM,GAAKL,GACnDM,MAAM,KAAKC,MAEtC,OAAOT,EAAaU,KAAO,GAAGL,MAChC,CAEAM,eAAeC,EAAkBZ,EAA4Ba,GAC3D,MAAMC,YAAEA,EAAWC,OAAEA,EAAMC,QAAEA,GAAYH,EAEzC,IAAKC,GAAaG,QAChB,MAAM,IAAIC,MAAM,0CAGlB,MAAMD,EAAUH,EAAYG,QAEtBhB,EAAgBe,EAAQf,cAExBC,EADM,IAAIC,IAAIF,GACOG,SAGrBe,EAAS,+BAFIjB,EAAeI,WAAW,KAAOJ,EAAeK,MAAM,GAAKL,uBAEAe,IACxEG,QA9DR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AAca,GACrCf,GAAW,GAGN+D,EAA4B,CAAIhD,EAAAA,EACzC,EAuDEiD,QArDFnD,eAAuBX,EAA4Ba,GAMjD,GALKf,UACGoD,EAAiBlD,EAAca,GACrCf,GAAW,GAGTiE,EAAY,CACd,MAAM/C,QAAEA,GAAYH,EAEd+B,EAAc7C,EAAeC,EADbgB,EAAQf,qBAGxBW,EAAkBZ,EAAca,SAEhCkD,EACJ,CACEX,OAAQ,CAACR,GACTS,QAAS,0CAEXxC,EAEJ,CACF,EAiCEmD,QA/BFrD,eAAuB6C,EAA6BC,GAElD,OAAO,IACT,EA6BEQ,QA3BFtD,eAAuB6C,EAA6BC,GAEpD,EA0BES,KArEFvD,eAAoB6C,EAA6BC,GAEjD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/semantic-release/brew/index.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\n\nimport { Octokit } from '@octokit/rest';\n//@ts-ignore\nimport { analyzeCommits as commitAnalyzerAnalyzeCommits } from '@semantic-release/commit-analyzer';\nimport {\n prepare as gitPrepare,\n verifyConditions as gitVerifyConditions,\n //@ts-ignore\n} from '@semantic-release/git';\n//@ts-ignore\nimport { generateNotes as notesGeneratorGenerateNotes } from '@semantic-release/release-notes-generator';\nimport {\n AddChannelContext,\n AnalyzeCommitsContext,\n FailContext,\n GenerateNotesContext,\n PrepareContext,\n PublishContext,\n SuccessContext,\n VerifyConditionsContext,\n} from 'semantic-release';\n\nimport { SemanticReleasePlugin } from '../types.js';\n\nconst analyzerConfig = {\n preset: 'conventionalcommits',\n parserOpts: {\n headerPattern: /^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$/,\n headerCorrespondence: ['type', 'exclamation1', 'scope', 'exclamation2', 'subject'],\n },\n releaseRules: [\n { type: 'feat', exclamation1: '!', release: 'major' },\n { type: 'feat', exclamation2: '!', release: 'major' },\n { type: 'feat', release: 'minor' },\n { type: 'fix', release: 'patch' },\n { type: 'docs', release: 'patch' },\n { type: 'style', release: 'patch' },\n { type: 'refactor', release: 'patch' },\n { type: 'perf', release: 'patch' },\n { type: 'test', release: 'patch' },\n { type: 'build', release: 'patch' },\n { type: 'ci', release: 'patch' },\n { type: 'chore', release: 'patch' },\n { type: 'revert', release: 'patch' },\n ],\n};\n\ntype PluginConfig = { tap?: string };\n\nlet verified = false;\n\nasync function createTag(_pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n if (!process.env.GITHUB_TOKEN) {\n throw new Error('GITHUB_TOKEN is not set in the environment.');\n }\n\n const { nextRelease, logger, options } = context;\n\n const tagName = `v${nextRelease.version}`;\n\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const [owner, repo] = new URL(repositoryUrl).pathname.slice(1).split('/');\n\n logger.log(`Creating tag ${tagName} using GitHub API...`);\n\n const octokit = new Octokit({\n auth: process.env.GITHUB_TOKEN, // Ensure GITHUB_TOKEN is available in the environment\n });\n\n try {\n const branchName = options.branch ?? 'main';\n logger.log(`Branch name: ${branchName}`);\n\n // Get the latest commit SHA from the default branch\n const { data: branch } = await octokit.repos.getBranch({\n owner,\n repo,\n branch: branchName,\n });\n\n const commitSha = branch.commit.sha;\n logger.log(`Latest commit SHA: ${commitSha}`);\n\n // Create the tag object\n logger.log(`Creating tag object for ${tagName}...`);\n await octokit.git.createTag({\n owner,\n repo,\n tag: tagName,\n message: `Release ${tagName}`,\n object: commitSha,\n type: 'commit',\n });\n\n // Create the reference for the tag\n logger.log(`Creating reference for tag ${tagName}...`);\n await octokit.git.createRef({\n owner,\n repo,\n ref: `refs/tags/${tagName}`,\n sha: commitSha,\n });\n\n logger.log(`Tag ${tagName} created successfully.`);\n } catch (error) {\n logger.error(`Failed to create tag ${tagName}: ${(error as Error).message}`);\n throw error;\n }\n}\n\nasync function calculateSha256(url: string, context: PrepareContext): Promise<string> {\n const { logger } = context;\n\n logger.log(`Calculating SHA256 for URL: ${url}`);\n\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch file. Status Code: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error('Response body is null.');\n }\n\n const hash = crypto.createHash('sha256');\n const reader = response.body.getReader();\n\n return new Promise((resolve, reject) => {\n function read() {\n reader\n .read()\n .then(({ done, value }) => {\n if (done) {\n resolve(hash.digest('hex'));\n return;\n }\n if (value) {\n hash.update(value);\n }\n read();\n })\n .catch(reject);\n }\n read();\n });\n}\n\nfunction getFormulaFile(pluginConfig: PluginConfig, repositoryUrl: string): string {\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n const project = repository.split('/').pop();\n\n return pluginConfig.tap ?? `${project}.rb`;\n}\n\nasync function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n const { nextRelease, logger, options } = context;\n\n if (!nextRelease?.version) {\n throw new Error('Next release version is not available.');\n }\n\n const tagName = `v${nextRelease.version}`;\n\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n\n const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/${tagName}`;\n const sha256 = await calculateSha256(tarUrl, context);\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n\n let formulaContent = fs.readFileSync(formulaFile, 'utf8');\n formulaContent = formulaContent.replace(/url \".*\"/, `url \"${tarUrl}\"`);\n formulaContent = formulaContent.replace(/sha256 \".*\"/, `sha256 \"${sha256}\"`);\n fs.writeFileSync(formulaFile, formulaContent);\n\n logger.log(`Updated formula with version ${tagName}, URL ${tarUrl}, and SHA256 ${sha256}`);\n}\n\nasync function addChannel(_pluginConfig: PluginConfig, _context: AddChannelContext): Promise<void> {\n //do nothing\n}\n\nasync function analyzeCommits(pluginConfig: PluginConfig, context: AnalyzeCommitsContext): Promise<string | false> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return commitAnalyzerAnalyzeCommits(analyzerConfig, context);\n}\n\nasync function fail(_pluginConfig: PluginConfig, _context: FailContext): Promise<void> {\n //do nothing\n}\n\nasync function generateNotes(pluginConfig: PluginConfig, context: GenerateNotesContext): Promise<string> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return notesGeneratorGenerateNotes({}, context);\n}\n\nasync function prepare(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n if (gitPrepare) {\n const { options } = context;\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n\n await createTag(pluginConfig, context);\n\n await updateFormulaFile(pluginConfig, context);\n\n await gitPrepare(\n {\n assets: [formulaFile],\n message: 'chore(release): ${nextRelease.version}',\n },\n context,\n );\n }\n}\n\nasync function publish(_pluginConfig: PluginConfig, _context: PublishContext): Promise<unknown> {\n //do nothing\n return null;\n}\n\nasync function success(_pluginConfig: PluginConfig, _context: SuccessContext): Promise<void> {\n //do nothing\n}\n\nasync function verifyConditions(pluginConfig: PluginConfig, context: VerifyConditionsContext): Promise<void> {\n if (gitVerifyConditions) {\n const { options } = context;\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n await gitVerifyConditions(\n {\n assets: [formulaFile],\n message: 'chore(release): ${nextRelease.version}',\n },\n context,\n );\n }\n verified = true;\n}\n\nconst plugin: SemanticReleasePlugin<{ tap: string }> = {\n addChannel,\n verifyConditions,\n analyzeCommits,\n generateNotes,\n prepare,\n publish,\n success,\n fail,\n};\n\nexport default plugin;\n"],"names":["analyzerConfig","preset","parserOpts","headerPattern","RegExp","headerCorrespondence","releaseRules","type","exclamation1","release","exclamation2","verified","getFormulaFile","pluginConfig","repositoryUrl","repositoryPath","URL","pathname","project","startsWith","slice","split","pop","tap","async","updateFormulaFile","context","nextRelease","logger","options","version","Error","tagName","tarUrl","sha256","url","log","response","fetch","ok","status","body","hash","crypto","createHash","reader","getReader","Promise","resolve","reject","read","then","done","value","digest","update","catch","calculateSha256","formulaFile","formulaContent","fs","readFileSync","replace","writeFileSync","verifyConditions","gitVerifyConditions","assets","message","plugin","addChannel","_pluginConfig","_context","analyzeCommits","commitAnalyzerAnalyzeCommits","generateNotes","notesGeneratorGenerateNotes","prepare","gitPrepare","process","env","GITHUB_TOKEN","owner","repo","octokit","Octokit","auth","branchName","branch","data","repos","getBranch","commitSha","commit","sha","git","createTag","tag","object","createRef","ref","error","publish","success","fail"],"mappings":"mSA0BA,MAAMA,EAAiB,CACrBC,OAAQ,sBACRC,WAAY,CACVC,cAAeC,OAAA,mGACfC,qBAAsB,CAAC,OAAQ,eAAgB,QAAS,eAAgB,YAE1EC,aAAc,CACZ,CAAEC,KAAM,OAAQC,aAAc,IAAKC,QAAS,SAC5C,CAAEF,KAAM,OAAQG,aAAc,IAAKD,QAAS,SAC5C,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,MAAOE,QAAS,SACxB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,WAAYE,QAAS,SAC7B,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,KAAME,QAAS,SACvB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,SAAUE,QAAS,WAM/B,IAAIE,GAAW,EAmGf,SAASC,EAAeC,EAA4BC,GAClD,MACMC,EADM,IAAIC,IAAIF,GACOG,SAErBC,GADaH,EAAeI,WAAW,KAAOJ,EAAeK,MAAM,GAAKL,GACnDM,MA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AQW,IAAIC,UAAU,CAC1Bd,QACAC,OACAc,IAAKhE,EACLmC,QAAS,WAAWnC,IACpBiE,OAAQN,EACRpF,KAAM,WAIRqB,EAAOQ,IAAI,8BAA8BJ,cACnCmD,EAAQW,IAAII,UAAU,CAC1BjB,QACAC,OACAiB,IAAK,aAAanE,IAClB6D,IAAKF,IAGP/D,EAAOQ,IAAI,OAAOJ,0BACpB,CAAE,MAAOoE,GAEP,MADAxE,EAAOwE,MAAM,wBAAwBpE,MAAaoE,EAAgBjC,WAC5DiC,CACR,CACF,CAgHUL,CAAUlF,EAAca,SAExBD,EAAkBZ,EAAca,SAEhCmD,EACJ,CACEX,OAAQ,CAACR,GACTS,QAAS,0CAEXzC,EAEJ,CACF,EAiCE2E,QA/BF7E,eAAuB8C,EAA6BC,GAElD,OAAO,IACT,EA6BE+B,QA3BF9E,eAAuB8C,EAA6BC,GAEpD,EA0BEgC,KAvEF/E,eAAoB8C,EAA6BC,GAEjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarsilla/commit-wizard",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"semantic-release": "^24"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
+
"@octokit/rest": "^21.1.1",
|
|
62
63
|
"chokidar": "^4.0.3",
|
|
63
64
|
"inquirer": "^8.2.6"
|
|
64
65
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
|
|
4
|
+
import { Octokit } from '@octokit/rest';
|
|
4
5
|
//@ts-ignore
|
|
5
6
|
import { analyzeCommits as commitAnalyzerAnalyzeCommits } from '@semantic-release/commit-analyzer';
|
|
6
7
|
import {
|
|
@@ -50,6 +51,65 @@ type PluginConfig = { tap?: string };
|
|
|
50
51
|
|
|
51
52
|
let verified = false;
|
|
52
53
|
|
|
54
|
+
async function createTag(_pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {
|
|
55
|
+
if (!process.env.GITHUB_TOKEN) {
|
|
56
|
+
throw new Error('GITHUB_TOKEN is not set in the environment.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { nextRelease, logger, options } = context;
|
|
60
|
+
|
|
61
|
+
const tagName = `v${nextRelease.version}`;
|
|
62
|
+
|
|
63
|
+
const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release
|
|
64
|
+
const [owner, repo] = new URL(repositoryUrl).pathname.slice(1).split('/');
|
|
65
|
+
|
|
66
|
+
logger.log(`Creating tag ${tagName} using GitHub API...`);
|
|
67
|
+
|
|
68
|
+
const octokit = new Octokit({
|
|
69
|
+
auth: process.env.GITHUB_TOKEN, // Ensure GITHUB_TOKEN is available in the environment
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const branchName = options.branch ?? 'main';
|
|
74
|
+
logger.log(`Branch name: ${branchName}`);
|
|
75
|
+
|
|
76
|
+
// Get the latest commit SHA from the default branch
|
|
77
|
+
const { data: branch } = await octokit.repos.getBranch({
|
|
78
|
+
owner,
|
|
79
|
+
repo,
|
|
80
|
+
branch: branchName,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const commitSha = branch.commit.sha;
|
|
84
|
+
logger.log(`Latest commit SHA: ${commitSha}`);
|
|
85
|
+
|
|
86
|
+
// Create the tag object
|
|
87
|
+
logger.log(`Creating tag object for ${tagName}...`);
|
|
88
|
+
await octokit.git.createTag({
|
|
89
|
+
owner,
|
|
90
|
+
repo,
|
|
91
|
+
tag: tagName,
|
|
92
|
+
message: `Release ${tagName}`,
|
|
93
|
+
object: commitSha,
|
|
94
|
+
type: 'commit',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Create the reference for the tag
|
|
98
|
+
logger.log(`Creating reference for tag ${tagName}...`);
|
|
99
|
+
await octokit.git.createRef({
|
|
100
|
+
owner,
|
|
101
|
+
repo,
|
|
102
|
+
ref: `refs/tags/${tagName}`,
|
|
103
|
+
sha: commitSha,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
logger.log(`Tag ${tagName} created successfully.`);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
logger.error(`Failed to create tag ${tagName}: ${(error as Error).message}`);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
53
113
|
async function calculateSha256(url: string, context: PrepareContext): Promise<string> {
|
|
54
114
|
const { logger } = context;
|
|
55
115
|
|
|
@@ -104,14 +164,14 @@ async function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareCon
|
|
|
104
164
|
throw new Error('Next release version is not available.');
|
|
105
165
|
}
|
|
106
166
|
|
|
107
|
-
const
|
|
167
|
+
const tagName = `v${nextRelease.version}`;
|
|
108
168
|
|
|
109
169
|
const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release
|
|
110
170
|
const url = new URL(repositoryUrl);
|
|
111
171
|
const repositoryPath = url.pathname;
|
|
112
172
|
const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;
|
|
113
173
|
|
|
114
|
-
const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags
|
|
174
|
+
const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/${tagName}`;
|
|
115
175
|
const sha256 = await calculateSha256(tarUrl, context);
|
|
116
176
|
const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);
|
|
117
177
|
|
|
@@ -120,7 +180,7 @@ async function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareCon
|
|
|
120
180
|
formulaContent = formulaContent.replace(/sha256 ".*"/, `sha256 "${sha256}"`);
|
|
121
181
|
fs.writeFileSync(formulaFile, formulaContent);
|
|
122
182
|
|
|
123
|
-
logger.log(`Updated formula with version ${
|
|
183
|
+
logger.log(`Updated formula with version ${tagName}, URL ${tarUrl}, and SHA256 ${sha256}`);
|
|
124
184
|
}
|
|
125
185
|
|
|
126
186
|
async function addChannel(_pluginConfig: PluginConfig, _context: AddChannelContext): Promise<void> {
|
|
@@ -160,6 +220,8 @@ async function prepare(pluginConfig: PluginConfig, context: PrepareContext): Pro
|
|
|
160
220
|
const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release
|
|
161
221
|
const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);
|
|
162
222
|
|
|
223
|
+
await createTag(pluginConfig, context);
|
|
224
|
+
|
|
163
225
|
await updateFormulaFile(pluginConfig, context);
|
|
164
226
|
|
|
165
227
|
await gitPrepare(
|