2019-05-17 18:20:48 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-05-17 09:13:16 +08:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
2019-05-17 18:20:48 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class GiteeController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="httpClientFactory"></param>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <param name="repoName"></param>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
/// <param name="label"></param>
|
|
|
|
|
/// <param name="color"></param>
|
2019-05-17 18:20:48 +08:00
|
|
|
|
/// <returns></returns>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
public async Task<ActionResult> Issues([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "LongbowEnterprise", [FromQuery]string repoName = "BootstrapAdmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange")
|
2019-05-17 18:20:48 +08:00
|
|
|
|
{
|
|
|
|
|
var client = httpClientFactory.CreateClient();
|
|
|
|
|
var content = await client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/issues");
|
|
|
|
|
var regex = Regex.Matches(content, "<div class='ui mini circular label'>([\\d]+)</div>", RegexOptions.IgnoreCase);
|
|
|
|
|
var labels = new string[] { "open", "closed", "rejected" };
|
|
|
|
|
var result = regex.Select((m, i) => $"{labels[i]} {m.Groups[1].Value}");
|
2019-05-18 12:46:57 +08:00
|
|
|
|
return new JsonResult(new { schemaVersion = 1, label, message = string.Join(" ", result), color });
|
2019-05-17 18:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="httpClientFactory"></param>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <param name="repoName"></param>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
/// <param name="label"></param>
|
|
|
|
|
/// <param name="color"></param>
|
2019-05-17 18:20:48 +08:00
|
|
|
|
/// <returns></returns>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
public async Task<ActionResult> Pulls([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "LongbowEnterprise", [FromQuery]string repoName = "BootstrapAdmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange")
|
2019-05-17 18:20:48 +08:00
|
|
|
|
{
|
|
|
|
|
var client = httpClientFactory.CreateClient();
|
|
|
|
|
var content = await client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/pulls");
|
|
|
|
|
var regex = Regex.Matches(content, "<div class='ui mini circular label'>([\\d]+)</div>", RegexOptions.IgnoreCase);
|
|
|
|
|
var labels = new string[] { "open", "merged", "closed" };
|
|
|
|
|
var result = regex.Select((m, i) => $"{labels[i]} {m.Groups[1].Value}");
|
2019-05-18 12:46:57 +08:00
|
|
|
|
return new JsonResult(new { schemaVersion = 1, label, message = string.Join(" ", result), color });
|
2019-05-17 18:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="httpClientFactory"></param>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <param name="repoName"></param>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
/// <param name="label"></param>
|
|
|
|
|
/// <param name="color"></param>
|
2019-05-17 18:20:48 +08:00
|
|
|
|
/// <returns></returns>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
public async Task<ActionResult> Releases([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "LongbowEnterprise", [FromQuery]string repoName = "BootstrapAdmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange")
|
2019-05-17 18:20:48 +08:00
|
|
|
|
{
|
|
|
|
|
var client = httpClientFactory.CreateClient();
|
|
|
|
|
var content = await client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/releases");
|
|
|
|
|
var regex = Regex.Match(content, $"<a href=\"/{userName}/{repoName}/releases/([^\\s]+)\" target=\"_blank\">", RegexOptions.IgnoreCase);
|
|
|
|
|
var result = regex.Groups[1].Value;
|
2019-05-18 12:46:57 +08:00
|
|
|
|
return new JsonResult(new { schemaVersion = 1, label, message = result, color });
|
2019-05-17 18:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="httpClientFactory"></param>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <param name="projName"></param>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
/// <param name="label"></param>
|
|
|
|
|
/// <param name="color"></param>
|
2019-05-17 18:20:48 +08:00
|
|
|
|
/// <returns></returns>
|
2019-05-18 12:46:57 +08:00
|
|
|
|
public async Task<ActionResult> Builds([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "ArgoZhang", [FromQuery]string projName = "bootstrapadmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange")
|
2019-05-17 18:20:48 +08:00
|
|
|
|
{
|
|
|
|
|
var client = httpClientFactory.CreateClient();
|
|
|
|
|
var content = await client.GetAsJsonAsync<AppveyorBuildResult>($"https://ci.appveyor.com/api/projects/{userName}/{projName}");
|
2019-05-18 12:46:57 +08:00
|
|
|
|
return new JsonResult(new { schemaVersion = 1, label, message = content.Build.Version, color });
|
2019-05-17 18:20:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
private class AppveyorBuildResult
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Build Build { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
private class Build
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Version { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|