+ * create release api
+ * {baseurl}/{owner}/{repo}
+ * https://git.mingliqiye.com/Actions/com.mingliqiye.gitea.releases/
+ * 注意: 创建release 不包含附件
+ * Note: Creating a release does not include attachments.
+ * api 地址 https://docs.gitea.com/zh-cn/api/#tag/repository/operation/repoCreateRelease
+ * api url https://docs.gitea.com/api/#tag/repository/operation/repoCreateRelease
+ * @param baseurl http://your.gitea.url 你的gitea地址 your gitea url
+ * @param owner 所属组织 organization
+ * @param repo 仓库名 repertoty
+ * @param createReleaseOption 创建发布选项 create release option
+ * @see Release
+ * @see CreateReleaseOption
+ * @return
+ *
+ */
+ public static Release createARelease(
+ String baseurl,
+ String owner,
+ String repo,
+ CreateReleaseOption createReleaseOption,
+ StringKeyValue authorization) {
+ String url = StringUtils.format("{}/api/v1/repos/{}/{}/releases", baseurl, owner, repo);
+ MediaType json = MediaType.parse("application/json; charset=utf-8");
+ log.info("{}", createReleaseOption);
+ String jsondata = JSON.toJSONString(createReleaseOption);
+ RequestBody body = RequestBody.create(jsondata, json);
+ Request request = new Request.Builder()
+ .url(url)
+ .addHeader(authorization.getKey(), authorization.getValue())
+ .post(body)
+ .build();
+ try {
+ Response response = client.newCall(request).execute();
+ if (response.isSuccessful()) {
+ log.info("CreateReleaseOK");
+ return JSON.parseObject(response.body().string(), Release.class);
+ } else {
+ log.error("CreateReleaseFailed");
+ log.error("Response.body:{}", response.body().string());
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static Attachment createAReleaseAttachment(
+ String baseurl,
+ String owner,
+ String repo,
+ Long id,
+ String name,
+ File attachment,
+ StringKeyValue authorization) {
+ String url = StringUtils.format("{}/api/v1/repos/{}/{}/releases/{}/assets", baseurl, owner, repo, id);
+
+ if (attachment == null) {
+ log.error("{}:{}", "attachment", "is a NullPointer");
+ return null;
+ }
+ log.info("ReleaseAttachment start {}", attachment.getAbsolutePath());
+ if (!attachment.exists()) {
+ log.error("{}:{}", attachment.getAbsolutePath(), "is not exist");
+ return null;
+ } else if (!attachment.isFile()) {
+ log.error("{}:{}", attachment.getAbsolutePath(), "is not a file");
+ return null;
+ } else if (!attachment.canRead()) {
+ log.error("{}:{}", attachment.getAbsolutePath(), "permission denied can't read");
+ return null;
+ }
+ RequestBody formBody = new MultipartBody.Builder()
+ .setType(MultipartBody.FORM)
+ .addFormDataPart("name", name)
+ .addFormDataPart(
+ "attachment",
+ attachment.getName(),
+ RequestBody.create(attachment, MediaType.parse("multipart/form-data")))
+ .build();
+ Request request = new Request.Builder()
+ .url(url)
+ .addHeader(authorization.getKey(), authorization.getValue())
+ .post(formBody)
+ .build();
+ try {
+ Response response = client.newCall(request).execute();
+ if (response.isSuccessful()) {
+ log.info("ReleaseAttachment {} OK", attachment.getAbsolutePath());
+ return JSON.parseObject(response.body().string(), Attachment.class);
+ } else {
+ log.error("ReleaseAttachment {} Failed", attachment.getAbsolutePath());
+ log.error("Response.body:{}", response.body().string());
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/mingliqiye/gitea/releases/utils/StringUtils.java b/src/main/java/com/mingliqiye/gitea/releases/utils/StringUtils.java
new file mode 100644
index 0000000..5fa7fc1
--- /dev/null
+++ b/src/main/java/com/mingliqiye/gitea/releases/utils/StringUtils.java
@@ -0,0 +1,9 @@
+package com.mingliqiye.gitea.releases.utils;
+
+import org.slf4j.helpers.MessageFormatter;
+
+public class StringUtils {
+ public static String format(String str, Object... args) {
+ return MessageFormatter.arrayFormat(str, args).getMessage();
+ }
+}
diff --git a/src/main/java/com/mingliqiye/libs/meta/ManifestReader.java b/src/main/java/com/mingliqiye/libs/meta/ManifestReader.java
new file mode 100644
index 0000000..78eb64a
--- /dev/null
+++ b/src/main/java/com/mingliqiye/libs/meta/ManifestReader.java
@@ -0,0 +1,97 @@
+package com.mingliqiye.libs.meta;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.jar.Manifest;
+
+/**
+ * 读取本 jar 的 Manifest 文件
+ * @see com.mingliqiye.libs.meta.ManifestReader
+ * com.mingliqiye.libs.Main
+ * @author MingLiPro|Armamem0t
+ * @version 1.0
+ */
+public final class ManifestReader {
+
+ private static final Manifest manifest = readManifest();
+ private static final ManifestData manifestData = new ManifestData(manifest);
+
+ public static ManifestData getManifestData() {
+ return ManifestReader.manifestData;
+ }
+
+ public static final class ManifestData {
+
+ private final Manifest manifest;
+
+ public ManifestData(Manifest manifest) {
+ this.manifest = manifest;
+ }
+
+ public String getVersion() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Implementation-Version");
+ }
+
+ public String getCopyright() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Copyright");
+ }
+
+ public String getVendor() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Implementation-Vendor");
+ }
+
+ public String getEmail() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Email");
+ }
+
+ public String getTitle() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Implementation-Title");
+ }
+
+ public String getEnv() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Env");
+ }
+
+ public String getMainClass() {
+ if (manifest == null) return null;
+ return manifest.getMainAttributes().getValue("Main-Class");
+ }
+
+ public boolean getDevelopment() {
+ String env = null;
+ if (manifest == null && (env = manifest.getMainAttributes().getValue("Env")) == null) return true;
+
+ if (env == null) return true;
+ return !env.equals("prod");
+ }
+
+ public Set