release-it-gitea 1.2.1 → 1.3.0
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.
- package/lib/global.d.d.ts +3 -3
- package/lib/index.d.ts +2 -9
- package/lib/index.js +12 -40
- package/package.json +1 -1
package/lib/global.d.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare module "release-it" {
|
|
2
2
|
interface Config {
|
|
3
|
-
getContext(path
|
|
3
|
+
getContext(path?: string): unknown;
|
|
4
|
+
setContext(path: string, value: unknown): void;
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
interface Context {
|
|
@@ -22,7 +23,6 @@ declare module "release-it" {
|
|
|
22
23
|
|
|
23
24
|
class Plugin {
|
|
24
25
|
config: Config;
|
|
25
|
-
context: Context;
|
|
26
26
|
log: {
|
|
27
27
|
error: (message: string) => void;
|
|
28
28
|
exec: (command: string) => void;
|
|
@@ -30,7 +30,6 @@ declare module "release-it" {
|
|
|
30
30
|
verbose: (message: string) => void;
|
|
31
31
|
warn: (message: string) => void;
|
|
32
32
|
};
|
|
33
|
-
options: GiteaConfig;
|
|
34
33
|
shell: {
|
|
35
34
|
exec: (command: string) => Promise<string>;
|
|
36
35
|
};
|
|
@@ -43,6 +42,7 @@ declare module "release-it" {
|
|
|
43
42
|
beforeBump(): Promise<void>;
|
|
44
43
|
beforeRelease(): Promise<void>;
|
|
45
44
|
bump(): Promise<void>;
|
|
45
|
+
getContext(path?: string): unknown;
|
|
46
46
|
getIncrement(): string;
|
|
47
47
|
getIncrementedVersion(): string;
|
|
48
48
|
getIncrementedVersionCI(): string;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { Plugin
|
|
1
|
+
import { Plugin } from 'release-it';
|
|
2
2
|
|
|
3
3
|
declare class GiteaPlugin extends Plugin {
|
|
4
|
-
private giteaConfig;
|
|
5
|
-
constructor(config: Config);
|
|
6
4
|
static isEnabled(config?: GiteaConfig): boolean;
|
|
7
5
|
/**
|
|
8
6
|
* 获取并验证 Gitea 配置信息
|
|
9
7
|
* @returns 验证后的 Gitea 配置对象
|
|
10
8
|
* @throws 当配置缺失或无效时抛出错误
|
|
11
9
|
*/
|
|
12
|
-
private
|
|
10
|
+
private get giteaConfig();
|
|
13
11
|
/**
|
|
14
12
|
* 从环境变量获取 API token.
|
|
15
13
|
* @returns API token 字符串
|
|
@@ -60,11 +58,6 @@ declare class GiteaPlugin extends Plugin {
|
|
|
60
58
|
* @returns 替换变量后的字符串
|
|
61
59
|
*/
|
|
62
60
|
private interpolate;
|
|
63
|
-
/**
|
|
64
|
-
* 初始化插件,验证配置和连接.
|
|
65
|
-
* @throws 当配置无效或连接失败时抛出错误
|
|
66
|
-
*/
|
|
67
|
-
init(): Promise<void>;
|
|
68
61
|
/**
|
|
69
62
|
* 执行发布操作,创建或更新 Gitea 发布.
|
|
70
63
|
* @throws 当发布创建失败时抛出错误
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import fetch from "node-fetch";
|
|
2
2
|
import { Plugin } from "release-it";
|
|
3
3
|
class GiteaPlugin extends Plugin {
|
|
4
|
-
giteaConfig;
|
|
5
|
-
constructor(config) {
|
|
6
|
-
super(config);
|
|
7
|
-
this.giteaConfig = this.getGiteaConfig();
|
|
8
|
-
}
|
|
9
4
|
static isEnabled(config) {
|
|
10
5
|
return Boolean(config?.release !== false);
|
|
11
6
|
}
|
|
@@ -14,20 +9,21 @@ class GiteaPlugin extends Plugin {
|
|
|
14
9
|
* @returns 验证后的 Gitea 配置对象
|
|
15
10
|
* @throws 当配置缺失或无效时抛出错误
|
|
16
11
|
*/
|
|
17
|
-
|
|
18
|
-
const gitea = this.
|
|
12
|
+
get giteaConfig() {
|
|
13
|
+
const gitea = this.getContext();
|
|
19
14
|
if (!gitea) {
|
|
20
15
|
throw new Error("Gitea \u914D\u7F6E\u672A\u627E\u5230");
|
|
21
16
|
}
|
|
17
|
+
const repo = this.getContext("repo");
|
|
22
18
|
const config = {
|
|
23
19
|
draft: gitea.draft ?? false,
|
|
24
20
|
host: gitea.host,
|
|
25
|
-
owner: gitea.owner ??
|
|
21
|
+
owner: gitea.owner ?? repo.owner,
|
|
26
22
|
prerelease: gitea.prerelease ?? false,
|
|
27
23
|
release: gitea.release !== false,
|
|
28
24
|
releaseNotes: gitea.releaseNotes ?? "${changelog}",
|
|
29
25
|
releaseTitle: gitea.releaseTitle ?? "v${version}",
|
|
30
|
-
repository: gitea.repository ??
|
|
26
|
+
repository: gitea.repository ?? repo.repository,
|
|
31
27
|
timeout: gitea.timeout ?? 3e4,
|
|
32
28
|
tokenRef: gitea.tokenRef ?? "GITEA_TOKEN"
|
|
33
29
|
};
|
|
@@ -158,33 +154,8 @@ class GiteaPlugin extends Plugin {
|
|
|
158
154
|
* @returns 替换变量后的字符串
|
|
159
155
|
*/
|
|
160
156
|
interpolate(template) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* 初始化插件,验证配置和连接.
|
|
165
|
-
* @throws 当配置无效或连接失败时抛出错误
|
|
166
|
-
*/
|
|
167
|
-
async init() {
|
|
168
|
-
this.log.info("\u521D\u59CB\u5316 Gitea \u63D2\u4EF6");
|
|
169
|
-
try {
|
|
170
|
-
this.getToken();
|
|
171
|
-
this.log.verbose("Gitea API token \u9A8C\u8BC1\u6210\u529F");
|
|
172
|
-
} catch (error) {
|
|
173
|
-
if (error instanceof Error) {
|
|
174
|
-
this.log.error(error.message);
|
|
175
|
-
}
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
try {
|
|
179
|
-
const endpoint = `/repos/${this.giteaConfig.owner}/${this.giteaConfig.repository}`;
|
|
180
|
-
await this.apiRequest(endpoint);
|
|
181
|
-
this.log.verbose("Gitea API \u8FDE\u63A5\u6D4B\u8BD5\u6210\u529F");
|
|
182
|
-
} catch (error) {
|
|
183
|
-
if (error instanceof Error) {
|
|
184
|
-
this.log.error(`\u65E0\u6CD5\u8FDE\u63A5\u5230 Gitea \u4ED3\u5E93: ${error.message}`);
|
|
185
|
-
}
|
|
186
|
-
throw error;
|
|
187
|
-
}
|
|
157
|
+
const context = this.config.getContext();
|
|
158
|
+
return template.replace(/\$\{version\}/g, context.version).replace(/\$\{latestVersion\}/g, context.latestVersion).replace(/\$\{changelog\}/g, context.changelog).replace(/\$\{name\}/g, context.name).replace(/\$\{repo\.owner\}/g, context.repo.owner).replace(/\$\{repo\.repository\}/g, context.repo.repository).replace(/\$\{branchName\}/g, context.branchName);
|
|
188
159
|
}
|
|
189
160
|
/**
|
|
190
161
|
* 执行发布操作,创建或更新 Gitea 发布.
|
|
@@ -195,7 +166,7 @@ class GiteaPlugin extends Plugin {
|
|
|
195
166
|
this.log.info("Gitea \u53D1\u5E03\u529F\u80FD\u5DF2\u7981\u7528");
|
|
196
167
|
return;
|
|
197
168
|
}
|
|
198
|
-
const tagName =
|
|
169
|
+
const tagName = this.config.getContext("tagName");
|
|
199
170
|
const releaseTitle = this.interpolate(
|
|
200
171
|
this.giteaConfig.releaseTitle ?? "v${version}"
|
|
201
172
|
);
|
|
@@ -221,7 +192,7 @@ class GiteaPlugin extends Plugin {
|
|
|
221
192
|
release = await this.createRelease(releaseData);
|
|
222
193
|
}
|
|
223
194
|
this.log.info(`\u2705 Gitea \u53D1\u5E03\u521B\u5EFA\u6210\u529F: ${release.html_url}`);
|
|
224
|
-
this.
|
|
195
|
+
this.config.setContext("releaseUrl", release.html_url);
|
|
225
196
|
} catch (error) {
|
|
226
197
|
if (error instanceof Error) {
|
|
227
198
|
this.log.error(`\u274C \u521B\u5EFA Gitea \u53D1\u5E03\u5931\u8D25: ${error.message}`);
|
|
@@ -233,8 +204,9 @@ class GiteaPlugin extends Plugin {
|
|
|
233
204
|
* 发布完成后的清理和通知操作
|
|
234
205
|
*/
|
|
235
206
|
async afterRelease() {
|
|
236
|
-
|
|
237
|
-
|
|
207
|
+
const releaseUrl = this.config.getContext("releaseUrl");
|
|
208
|
+
if (releaseUrl) {
|
|
209
|
+
this.log.info(`\u{1F389} \u53D1\u5E03\u5B8C\u6210! \u67E5\u770B\u53D1\u5E03: ${releaseUrl}`);
|
|
238
210
|
}
|
|
239
211
|
return Promise.resolve();
|
|
240
212
|
}
|