Merge branch 'dev'
This commit is contained in:
commit
910bdfc054
13
src/CodeRelease/CodeRelease/.config/dotnet-tools.json
Normal file
13
src/CodeRelease/CodeRelease/.config/dotnet-tools.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "8.0.6",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
],
|
||||
"rollForward": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
using CodeRelease.BLL;
|
||||
using CodeRelease.Model;
|
||||
using CodeRelease.Utile;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
namespace CodeRelease.Controllers
|
||||
{
|
||||
|
||||
|
|
@ -16,11 +26,68 @@ namespace CodeRelease.Controllers
|
|||
/// 测试
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<object> Test()
|
||||
public async Task<object> Test([FromBody] object data)
|
||||
{
|
||||
var jsonStr = data.ToString();
|
||||
var jObject = JsonConvert.DeserializeObject<JObject>(jsonStr);
|
||||
LinuxExecuteCommand linuxExecuteCommand = new LinuxExecuteCommand();
|
||||
var obj = await linuxExecuteCommand.ExecuteCommand("make test -f /disk/CodeRelease/test/makefile");
|
||||
return obj;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
/// <summary>
|
||||
/// 发布
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<object> ReleaseAction([FromBody] object data, [FromServices] GiteaWebhookConfigModel giteaWebhookConfig)
|
||||
{
|
||||
JsonSerializerSettings settings = new JsonSerializerSettings
|
||||
{
|
||||
//MaxDepth = 64 // 设置一个足够大的值,默认值是 32
|
||||
ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new CamelCaseNamingStrategy()
|
||||
}
|
||||
};
|
||||
var jsonStr = data.ToString() ?? "";
|
||||
var releaseAction = JsonConvert.DeserializeObject<PublishAction>(jsonStr, settings);
|
||||
|
||||
if (releaseAction != null)
|
||||
{
|
||||
if (releaseAction.Action == "published")
|
||||
{
|
||||
if (releaseAction.Release.Assets?.Count > 0)
|
||||
{
|
||||
var url = releaseAction.Release.Assets[0].BrowserDownloadUrl;
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
var version = releaseAction.Release.TagName;
|
||||
var fileName = Path.GetFileName(url);
|
||||
var download = giteaWebhookConfig.BrowserDownloadFileUrl + version + "/";
|
||||
if (!Directory.Exists(download))
|
||||
{
|
||||
Directory.CreateDirectory(download);
|
||||
}
|
||||
FileDownloader fileDownloader = new FileDownloader();
|
||||
//giteaWebhookConfig.BrowserDownloadFileUrl.Replace("{version}", version);
|
||||
await fileDownloader.DownloadFileAsync(url, download + fileName);
|
||||
ZipExtractor extractor = new ZipExtractor();
|
||||
var temp = fileName.Substring(0, fileName.LastIndexOf("."));
|
||||
extractor.ExtractZipFile(download + fileName, download + "/" + temp);
|
||||
var mingling = giteaWebhookConfig.MakeFile.Replace("{version}", version).Replace("{dir_file_path}", download + "/" + temp + "/");
|
||||
LinuxExecuteCommand linuxExecuteCommand = new LinuxExecuteCommand();
|
||||
//make public version=0.0.1 dir_file_path=/
|
||||
var obj = await linuxExecuteCommand.ExecuteCommand(mingling);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
970
src/CodeRelease/CodeRelease/Model/GiteaWebhook.cs
Normal file
970
src/CodeRelease/CodeRelease/Model/GiteaWebhook.cs
Normal file
|
|
@ -0,0 +1,970 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
namespace CodeRelease.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 发布动作类
|
||||
/// </summary>
|
||||
public class PublishAction
|
||||
{
|
||||
/// <summary>
|
||||
/// 发布的动作
|
||||
/// </summary>
|
||||
[JsonProperty("action")]
|
||||
public string Action { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布信息
|
||||
/// </summary>
|
||||
[JsonProperty("release")]
|
||||
public Release Release { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库信息
|
||||
/// </summary>
|
||||
[JsonProperty("repository")]
|
||||
public Repository Repository { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发送者信息
|
||||
/// </summary>
|
||||
[JsonProperty("sender")]
|
||||
public Sender Sender { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布信息类
|
||||
/// </summary>
|
||||
public class Release
|
||||
{
|
||||
/// <summary>
|
||||
/// 发布ID
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标签名称
|
||||
/// </summary>
|
||||
[JsonProperty("tag_name")]
|
||||
public string TagName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 目标分支
|
||||
/// </summary>
|
||||
[JsonProperty("target_commitish")]
|
||||
public string TargetCommitish { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布名称
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布描述
|
||||
/// </summary>
|
||||
[JsonProperty("body")]
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布URL
|
||||
/// </summary>
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布HTML URL
|
||||
/// </summary>
|
||||
[JsonProperty("html_url")]
|
||||
public string HtmlUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// tarball文件URL
|
||||
/// </summary>
|
||||
[JsonProperty("tarball_url")]
|
||||
public string TarballUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// zipball文件URL
|
||||
/// </summary>
|
||||
[JsonProperty("zipball_url")]
|
||||
public string ZipballUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传URL
|
||||
/// </summary>
|
||||
[JsonProperty("upload_url")]
|
||||
public string UploadUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为草稿
|
||||
/// </summary>
|
||||
[JsonProperty("draft")]
|
||||
public bool Draft { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为预发布
|
||||
/// </summary>
|
||||
[JsonProperty("prerelease")]
|
||||
public bool Prerelease { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[JsonProperty("created_at")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布时间
|
||||
/// </summary>
|
||||
[JsonProperty("published_at")]
|
||||
public DateTime PublishedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 作者信息
|
||||
/// </summary>
|
||||
[JsonProperty("author")]
|
||||
public Author Author { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产列表
|
||||
/// </summary>
|
||||
[JsonProperty("assets")]
|
||||
public List<Asset> Assets { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 作者信息类
|
||||
/// </summary>
|
||||
public class Author
|
||||
{
|
||||
/// <summary>
|
||||
/// 作者ID
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名
|
||||
/// </summary>
|
||||
[JsonProperty("login")]
|
||||
public string Login { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名称
|
||||
/// </summary>
|
||||
[JsonProperty("login_name")]
|
||||
public string LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源ID
|
||||
/// </summary>
|
||||
[JsonProperty("source_id")]
|
||||
public int SourceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 全名
|
||||
/// </summary>
|
||||
[JsonProperty("full_name")]
|
||||
public string FullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱
|
||||
/// </summary>
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 头像URL
|
||||
/// </summary>
|
||||
[JsonProperty("avatar_url")]
|
||||
public string AvatarUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTML URL
|
||||
/// </summary>
|
||||
[JsonProperty("html_url")]
|
||||
public string HtmlUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 语言
|
||||
/// </summary>
|
||||
[JsonProperty("language")]
|
||||
public string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为管理员
|
||||
/// </summary>
|
||||
[JsonProperty("is_admin")]
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后登录时间
|
||||
/// </summary>
|
||||
[JsonProperty("last_login")]
|
||||
public DateTime LastLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[JsonProperty("created")]
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否受限
|
||||
/// </summary>
|
||||
[JsonProperty("restricted")]
|
||||
public bool Restricted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否活跃
|
||||
/// </summary>
|
||||
[JsonProperty("active")]
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止登录
|
||||
/// </summary>
|
||||
[JsonProperty("prohibit_login")]
|
||||
public bool ProhibitLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
[JsonProperty("location")]
|
||||
public string Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 个人网站
|
||||
/// </summary>
|
||||
[JsonProperty("website")]
|
||||
public string Website { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可见性
|
||||
/// </summary>
|
||||
[JsonProperty("visibility")]
|
||||
public string Visibility { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关注者数量
|
||||
/// </summary>
|
||||
[JsonProperty("followers_count")]
|
||||
public int FollowersCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关注数量
|
||||
/// </summary>
|
||||
[JsonProperty("following_count")]
|
||||
public int FollowingCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 收藏的仓库数量
|
||||
/// </summary>
|
||||
[JsonProperty("starred_repos_count")]
|
||||
public int StarredReposCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资产信息类
|
||||
/// </summary>
|
||||
public class Asset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资产ID
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产名称
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产大小
|
||||
/// </summary>
|
||||
[JsonProperty("size")]
|
||||
public long Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载次数
|
||||
/// </summary>
|
||||
[JsonProperty("download_count")]
|
||||
public int DownloadCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[JsonProperty("created_at")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资产UUID
|
||||
/// </summary>
|
||||
[JsonProperty("uuid")]
|
||||
public string Uuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 浏览器下载URL
|
||||
/// </summary>
|
||||
[JsonProperty("browser_download_url")]
|
||||
public string BrowserDownloadUrl { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 仓库信息类
|
||||
/// </summary>
|
||||
public class Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 仓库ID
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 拥有者信息
|
||||
/// </summary>
|
||||
[JsonProperty("owner")]
|
||||
public Owner Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库名称
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库全名
|
||||
/// </summary>
|
||||
[JsonProperty("full_name")]
|
||||
public string FullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库描述
|
||||
/// </summary>
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库是否为空
|
||||
/// </summary>
|
||||
[JsonProperty("empty")]
|
||||
public bool Empty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为私有仓库
|
||||
/// </summary>
|
||||
[JsonProperty("private")]
|
||||
public bool Private { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为派生仓库
|
||||
/// </summary>
|
||||
[JsonProperty("fork")]
|
||||
public bool Fork { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为模板仓库
|
||||
/// </summary>
|
||||
[JsonProperty("template")]
|
||||
public bool Template { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父仓库
|
||||
/// </summary>
|
||||
[JsonProperty("parent")]
|
||||
public object Parent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为镜像仓库
|
||||
/// </summary>
|
||||
[JsonProperty("mirror")]
|
||||
public bool Mirror { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库大小
|
||||
/// </summary>
|
||||
[JsonProperty("size")]
|
||||
public long Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库语言
|
||||
/// </summary>
|
||||
[JsonProperty("language")]
|
||||
public string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库语言URL
|
||||
/// </summary>
|
||||
[JsonProperty("languages_url")]
|
||||
public string LanguagesUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库HTML URL
|
||||
/// </summary>
|
||||
[JsonProperty("html_url")]
|
||||
public string HtmlUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库API URL
|
||||
/// </summary>
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库链接
|
||||
/// </summary>
|
||||
[JsonProperty("link")]
|
||||
public string Link { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库SSH URL
|
||||
/// </summary>
|
||||
[JsonProperty("ssh_url")]
|
||||
public string SshUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库克隆 URL
|
||||
/// </summary>
|
||||
[JsonProperty("clone_url")]
|
||||
public string CloneUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始 URL
|
||||
/// </summary>
|
||||
[JsonProperty("original_url")]
|
||||
public string OriginalUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库网站
|
||||
/// </summary>
|
||||
[JsonProperty("website")]
|
||||
public string Website { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星标数量
|
||||
/// </summary>
|
||||
[JsonProperty("stars_count")]
|
||||
public int StarsCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 派生数量
|
||||
/// </summary>
|
||||
[JsonProperty("forks_count")]
|
||||
public int ForksCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关注者数量
|
||||
/// </summary>
|
||||
[JsonProperty("watchers_count")]
|
||||
public int WatchersCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开放问题数量
|
||||
/// </summary>
|
||||
[JsonProperty("open_issues_count")]
|
||||
public int OpenIssuesCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开放PR数量
|
||||
/// </summary>
|
||||
[JsonProperty("open_pr_counter")]
|
||||
public int OpenPrCounter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布数量
|
||||
/// </summary>
|
||||
[JsonProperty("release_counter")]
|
||||
public int ReleaseCounter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认分支
|
||||
/// </summary>
|
||||
[JsonProperty("default_branch")]
|
||||
public string DefaultBranch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否存档
|
||||
/// </summary>
|
||||
[JsonProperty("archived")]
|
||||
public bool Archived { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[JsonProperty("created_at")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
[JsonProperty("updated_at")]
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 存档时间
|
||||
/// </summary>
|
||||
[JsonProperty("archived_at")]
|
||||
public DateTime ArchivedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 权限信息
|
||||
/// </summary>
|
||||
[JsonProperty("permissions")]
|
||||
public Permissions Permissions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有问题跟踪
|
||||
/// </summary>
|
||||
[JsonProperty("has_issues")]
|
||||
public bool HasIssues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内部问题跟踪器
|
||||
/// </summary>
|
||||
[JsonProperty("internal_tracker")]
|
||||
public InternalTracker InternalTracker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有Wiki
|
||||
/// </summary>
|
||||
[JsonProperty("has_wiki")]
|
||||
public bool HasWiki { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有PR
|
||||
/// </summary>
|
||||
[JsonProperty("has_pull_requests")]
|
||||
public bool HasPullRequests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有项目
|
||||
/// </summary>
|
||||
[JsonProperty("has_projects")]
|
||||
public bool HasProjects { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 项目模式
|
||||
/// </summary>
|
||||
[JsonProperty("projects_mode")]
|
||||
public string ProjectsMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有发布
|
||||
/// </summary>
|
||||
[JsonProperty("has_releases")]
|
||||
public bool HasReleases { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有包
|
||||
/// </summary>
|
||||
[JsonProperty("has_packages")]
|
||||
public bool HasPackages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有动作
|
||||
/// </summary>
|
||||
[JsonProperty("has_actions")]
|
||||
public bool HasActions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否忽略空白冲突
|
||||
/// </summary>
|
||||
[JsonProperty("ignore_whitespace_conflicts")]
|
||||
public bool IgnoreWhitespaceConflicts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许合并提交
|
||||
/// </summary>
|
||||
[JsonProperty("allow_merge_commits")]
|
||||
public bool AllowMergeCommits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许变基
|
||||
/// </summary>
|
||||
[JsonProperty("allow_rebase")]
|
||||
public bool AllowRebase { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许显式变基
|
||||
/// </summary>
|
||||
[JsonProperty("allow_rebase_explicit")]
|
||||
public bool AllowRebaseExplicit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许快速前进合并
|
||||
/// </summary>
|
||||
[JsonProperty("allow_squash_merge")]
|
||||
public bool AllowSquashMerge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否仅允许快速前进合并
|
||||
/// </summary>
|
||||
[JsonProperty("allow_fast_forward_only_merge")]
|
||||
public bool AllowFastForwardOnlyMerge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许变基更新
|
||||
/// </summary>
|
||||
[JsonProperty("allow_rebase_update")]
|
||||
public bool AllowRebaseUpdate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否在合并后默认删除分支
|
||||
/// </summary>
|
||||
[JsonProperty("default_delete_branch_after_merge")]
|
||||
public bool DefaultDeleteBranchAfterMerge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认合并样式
|
||||
/// </summary>
|
||||
[JsonProperty("default_merge_style")]
|
||||
public string DefaultMergeStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否默认允许维护者编辑
|
||||
/// </summary>
|
||||
[JsonProperty("default_allow_maintainer_edit")]
|
||||
public bool DefaultAllowMaintainerEdit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 头像URL
|
||||
/// </summary>
|
||||
[JsonProperty("avatar_url")]
|
||||
public string AvatarUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为内部仓库
|
||||
/// </summary>
|
||||
[JsonProperty("internal")]
|
||||
public bool Internal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 镜像间隔
|
||||
/// </summary>
|
||||
[JsonProperty("mirror_interval")]
|
||||
public string MirrorInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对象格式名称
|
||||
/// </summary>
|
||||
[JsonProperty("object_format_name")]
|
||||
public string ObjectFormatName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 镜像更新时间
|
||||
/// </summary>
|
||||
[JsonProperty("mirror_updated")]
|
||||
public DateTime MirrorUpdated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库转移
|
||||
/// </summary>
|
||||
[JsonProperty("repo_transfer")]
|
||||
public object RepoTransfer { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 仓库所有者
|
||||
/// </summary>
|
||||
public class Owner
|
||||
{
|
||||
/// <summary>
|
||||
/// 所有者ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名
|
||||
/// </summary>
|
||||
public string Login { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名称
|
||||
/// </summary>
|
||||
public string LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源ID
|
||||
/// </summary>
|
||||
public int SourceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 全名
|
||||
/// </summary>
|
||||
public string FullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱
|
||||
/// </summary>
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 头像 URL
|
||||
/// </summary>
|
||||
public string AvatarUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTML URL
|
||||
/// </summary>
|
||||
public string HtmlUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 语言
|
||||
/// </summary>
|
||||
public string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为管理员
|
||||
/// </summary>
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后登录时间
|
||||
/// </summary>
|
||||
public DateTime LastLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否受限
|
||||
/// </summary>
|
||||
public bool Restricted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否活跃
|
||||
/// </summary>
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止登录
|
||||
/// </summary>
|
||||
public bool ProhibitLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
public string Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站
|
||||
/// </summary>
|
||||
public string Website { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可见性
|
||||
/// </summary>
|
||||
public string Visibility { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 粉丝数量
|
||||
/// </summary>
|
||||
public int FollowersCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关注数量
|
||||
/// </summary>
|
||||
public int FollowingCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星标仓库数量
|
||||
/// </summary>
|
||||
public int StarredReposCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 权限
|
||||
/// </summary>
|
||||
public class Permissions
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否为管理员
|
||||
/// </summary>
|
||||
public bool Admin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许推送
|
||||
/// </summary>
|
||||
public bool Push { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许拉取
|
||||
/// </summary>
|
||||
public bool Pull { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部跟踪器
|
||||
/// </summary>
|
||||
public class InternalTracker
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否启用时间跟踪
|
||||
/// </summary>
|
||||
public bool EnableTimeTracker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否仅允许贡献者跟踪时间
|
||||
/// </summary>
|
||||
public bool AllowOnlyContributorsToTrackTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用问题依赖
|
||||
/// </summary>
|
||||
public bool EnableIssueDependencies { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 触发发布的用户
|
||||
/// </summary>
|
||||
public class Sender
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名
|
||||
/// </summary>
|
||||
public string Login { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录名称
|
||||
/// </summary>
|
||||
public string LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源ID
|
||||
/// </summary>
|
||||
public int SourceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 全名
|
||||
/// </summary>
|
||||
public string FullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱
|
||||
/// </summary>
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 头像 URL
|
||||
/// </summary>
|
||||
public string AvatarUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTML URL
|
||||
/// </summary>
|
||||
public string HtmlUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 语言
|
||||
/// </summary>
|
||||
public string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为管理员
|
||||
/// </summary>
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后登录时间
|
||||
/// </summary>
|
||||
public DateTime LastLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否受限
|
||||
/// </summary>
|
||||
public bool Restricted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否活跃
|
||||
/// </summary>
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止登录
|
||||
/// </summary>
|
||||
public bool ProhibitLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
public string Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站
|
||||
/// </summary>
|
||||
public string Website { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可见性
|
||||
/// </summary>
|
||||
public string Visibility { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 粉丝数量
|
||||
/// </summary>
|
||||
public int FollowersCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关注数量
|
||||
/// </summary>
|
||||
public int FollowingCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星标仓库数量
|
||||
/// </summary>
|
||||
public int StarredReposCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
src/CodeRelease/CodeRelease/Model/GiteaWebhookConfigModel.cs
Normal file
21
src/CodeRelease/CodeRelease/Model/GiteaWebhookConfigModel.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
namespace CodeRelease.Model
|
||||
{
|
||||
public class GiteaWebhookConfigModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 名字
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// make命令
|
||||
/// </summary>
|
||||
public string MakeFile { get; set; }
|
||||
/// <summary>
|
||||
/// 下载后地址
|
||||
/// </summary>
|
||||
public string BrowserDownloadFileUrl { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,14 @@
|
|||
using CodeRelease.Model;
|
||||
using CodeRelease.Utile;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
var giteaWebhookConfigModelList = builder.Configuration.GetSection("GiteaWebhookConfig").Get<List<GiteaWebhookConfigModel>>() ?? new List<GiteaWebhookConfigModel>();
|
||||
builder.Services.AddSingleton(giteaWebhookConfigModelList);
|
||||
builder.Services.AddScoped<GiteaWebhookConfigModel>();
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
|
@ -19,6 +26,7 @@ if (app.Environment.IsDevelopment())
|
|||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
app.UseMiddleware<GiteaWebhookConfigMiddleware>();
|
||||
app.MapGet("/", () =>
|
||||
{
|
||||
return "ÇëÇó³É¹¦";
|
||||
|
|
|
|||
51
src/CodeRelease/CodeRelease/Utile/FileDownloader.cs
Normal file
51
src/CodeRelease/CodeRelease/Utile/FileDownloader.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
namespace CodeRelease.Utile
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载文件
|
||||
/// </summary>
|
||||
public class FileDownloader
|
||||
{
|
||||
|
||||
|
||||
public FileDownloader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件并将其保存到指定路径。
|
||||
/// </summary>
|
||||
/// <param name="fileUrl">要下载的文件的 URL。</param>
|
||||
/// <param name="destinationFilePath">保存文件的路径。</param>
|
||||
/// <returns>异步任务。</returns>
|
||||
public async Task<bool> DownloadFileAsync(string fileUrl, string destinationFilePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (HttpClient _client = new HttpClient())
|
||||
{
|
||||
// 发送 HTTP GET 请求
|
||||
HttpResponseMessage response = await _client.GetAsync(fileUrl);
|
||||
|
||||
// 确认响应状态是成功
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 读取响应内容为字节数组
|
||||
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
|
||||
// 将字节数组写入文件
|
||||
await File.WriteAllBytesAsync(destinationFilePath, fileBytes);
|
||||
}
|
||||
return true;
|
||||
//Console.WriteLine("文件下载成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Console.WriteLine($"文件下载失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
using CodeRelease.Model;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace CodeRelease.Utile
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GiteaWebhookConfigMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
|
||||
public GiteaWebhookConfigMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context,
|
||||
List<GiteaWebhookConfigModel> giteaWebhookConfigModels,
|
||||
GiteaWebhookConfigModel giteaWebhookConfig)
|
||||
{
|
||||
context.Request.Headers.TryGetValue("Authorization", out var authorization);
|
||||
var key = authorization.ToString();
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
var tempgiteaWebhookConfig = giteaWebhookConfigModels.FirstOrDefault(it => it.Name == key);
|
||||
if (tempgiteaWebhookConfig == null)
|
||||
{
|
||||
if (giteaWebhookConfigModels.Count > 0)
|
||||
{
|
||||
tempgiteaWebhookConfig = giteaWebhookConfigModels[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
tempgiteaWebhookConfig = new GiteaWebhookConfigModel();
|
||||
}
|
||||
}
|
||||
giteaWebhookConfig.BrowserDownloadFileUrl = tempgiteaWebhookConfig.BrowserDownloadFileUrl;
|
||||
giteaWebhookConfig.Name = tempgiteaWebhookConfig.Name;
|
||||
giteaWebhookConfig.MakeFile = tempgiteaWebhookConfig.MakeFile;
|
||||
}
|
||||
await _next(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
37
src/CodeRelease/CodeRelease/Utile/ZipExtractor.cs
Normal file
37
src/CodeRelease/CodeRelease/Utile/ZipExtractor.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
namespace CodeRelease.Utile
|
||||
{
|
||||
/// <summary>
|
||||
/// 解压文件
|
||||
/// </summary>
|
||||
public class ZipExtractor
|
||||
{
|
||||
/// <summary>
|
||||
/// 解压ZIP文件到指定目录。
|
||||
/// </summary>
|
||||
/// <param name="zipFilePath">ZIP 文件路径。</param>
|
||||
/// <param name="extractPath">解压目标目录。</param>
|
||||
public void ExtractZipFile(string zipFilePath, string extractPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 确保目标目录存在
|
||||
if (!Directory.Exists(extractPath))
|
||||
{
|
||||
Directory.CreateDirectory(extractPath);
|
||||
}
|
||||
|
||||
// 解压缩文件
|
||||
ZipFile.ExtractToDirectory(zipFilePath, extractPath);
|
||||
|
||||
//Console.WriteLine("文件解压成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Console.WriteLine($"文件解压失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,8 +11,26 @@
|
|||
"Http": {
|
||||
"Url": "http://*:5240"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
//web 钩子配置
|
||||
"GiteaWebhookConfig": [
|
||||
{
|
||||
"Name": "coderelease",
|
||||
//make 文件位置
|
||||
"MakeFile": "make public version={version} dir_file_path={dir_file_path} -f /disk/CodeRelease/test/makefile",
|
||||
//发布文件下载位置
|
||||
"BrowserDownloadFileUrl": "I:/Gitea/test/disk/aiweb/"
|
||||
//
|
||||
},
|
||||
{
|
||||
"Name": "aiweb",
|
||||
//make 文件位置
|
||||
"MakeFile": "make public version={version} dir_file_path={dir_file_path} -f /disk/CodeRelease/test/makefile",
|
||||
//发布文件下载位置
|
||||
"BrowserDownloadFileUrl": "I:/Gitea/test/disk/aiweb/"
|
||||
//
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,21 @@
|
|||
SHELL=/usr/bin/env bash
|
||||
date_dir_name = $(shell date +"%Y%m%d-%H%M%S")
|
||||
dir_file_path=/disk
|
||||
backups_dir_path=/disk/web/backups
|
||||
version=0.0.1
|
||||
server_dir_path=/var/www/web/
|
||||
test:
|
||||
@echo $(date_dir_name)
|
||||
@echo $(dir_file)
|
||||
|
||||
|
||||
|
||||
public:
|
||||
# make public version=0.0.1 dir_file_path=/
|
||||
#make var dir_file_path=aaa
|
||||
@echo $(date_dir_name)
|
||||
# 创建备份文件夹
|
||||
mkdir -p $(backups_dir_path)/$(version)/$(date_dir_name)
|
||||
# 从服务器同步到本地,备份
|
||||
rsync -avz ubuntu@101.43.19.200:$(server_dir_path) $(backups_dir_path)/$(version)/$(date_dir_name)
|
||||
# 从本地同步到服务器
|
||||
rsync -avz $(dir_file_path) ubuntu@101.43.19.200:$(server_dir_path)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user