Skip to content

Commit

Permalink
Merge pull request #1 from dotnet-campus/t/lindexi/ChangeProperty
Browse files Browse the repository at this point in the history
优化命名
  • Loading branch information
lindexi committed Mar 23, 2020
2 parents da88f6b + 634d061 commit eb5a946
Show file tree
Hide file tree
Showing 5 changed files with 512 additions and 173 deletions.
4 changes: 2 additions & 2 deletions DotNetGitLabWebHook/Business/Check/FileChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public FileChecker(RepoManager repoManager)

public void Check(GitLabMergeRequest gitLabMergeRequest)
{
var repositoryUrl = gitLabMergeRequest.RawProperty.repository.url;
var repoFolder = RepoManager.GetRepo(repositoryUrl, gitLabMergeRequest.RawProperty.repository.name);
var repositoryUrl = gitLabMergeRequest.RawProperty.Repository.Url;
var repoFolder = RepoManager.GetRepo(repositoryUrl, gitLabMergeRequest.RawProperty.Repository.Name);

var git = new Git(repoFolder);

Expand Down
3 changes: 1 addition & 2 deletions DotNetGitLabWebHook/Business/GitLabMRCheckerFlow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DotNetGitLabWebHook.Model;
using DotNetGitLabWebHookToMatterMost.Business.Check;
using DotNetGitLabWebHookToMatterMost.Business.Check;
using DotNetGitLabWebHookToMatterMost.Model;
using Microsoft.Extensions.Configuration;

Expand Down
10 changes: 5 additions & 5 deletions DotNetGitLabWebHook/Business/Notify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Notify(IConfiguration configuration)
public IConfiguration Configuration { get; }
public void NotifyMatterMost(GitLabMergeRequest gitLabMergeRequest)
{
var state = gitLabMergeRequest.RawProperty.object_attributes.state;
var state = gitLabMergeRequest.RawProperty.ObjectAttributes.State;

string text = "";

Expand All @@ -28,7 +28,7 @@ public void NotifyMatterMost(GitLabMergeRequest gitLabMergeRequest)
}
else if (state == "merged")
{
var username = gitLabMergeRequest.RawProperty.user.username;
var username = gitLabMergeRequest.RawProperty.User.Username;
text = $"恭喜@{username} [{gitLabMergeRequest.CommonProperty.Title}]({gitLabMergeRequest.CommonProperty.MergeRequestUrl}) 已经合并";
}
else
Expand All @@ -37,11 +37,11 @@ public void NotifyMatterMost(GitLabMergeRequest gitLabMergeRequest)
//var action = gitLabMergeRequest.RawProperty.object_attributes.action;
// action 有三个值 update open reopen

var assignees = gitLabMergeRequest.RawProperty.assignees;
var assigneeList = new List<string> { gitLabMergeRequest.RawProperty.object_attributes.assignee?.username };
var assignees = gitLabMergeRequest.RawProperty.Assignees;
var assigneeList = new List<string> { gitLabMergeRequest.RawProperty.ObjectAttributes.Assignee?.Username };
if (assignees != null)
{
assigneeList.AddRange(assignees.Select(temp => temp.username));
assigneeList.AddRange(assignees.Select(temp => temp.Username));
}

var assigneeUsername = string.Join(' ',
Expand Down
23 changes: 11 additions & 12 deletions DotNetGitLabWebHook/Controllers/GitLabWebHookController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DotNetGitLabWebHook.Model;
using DotNetGitLabWebHookToMatterMost.Business;
using DotNetGitLabWebHookToMatterMost.Business;
using DotNetGitLabWebHookToMatterMost.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -31,24 +30,24 @@ public IActionResult MergeRequest(object obj)
var rootobject =
JsonConvert.DeserializeObject<GitLabMergeRequest.Rootobject>(str);

if (rootobject.object_kind == "merge_request")
if (rootobject.ObjectKind == "merge_request")
{
var objectAttributes = rootobject.object_attributes;
var objectAttributes = rootobject.ObjectAttributes;

var sourceGitSshUrl = objectAttributes.source.git_ssh_url;
var sourceBranch = objectAttributes.source_branch;
var sourceGitSshUrl = objectAttributes.Source.GitSshUrl;
var sourceBranch = objectAttributes.SourceBranch;

// 最后提交号
var lastCommitId = objectAttributes.last_commit.id;
var lastCommitId = objectAttributes.LastCommit.Id;

var targetGitSshUrl = objectAttributes.target.git_ssh_url;
var targetBranch = objectAttributes.target_branch;
var targetGitSshUrl = objectAttributes.Target.GitSshUrl;
var targetBranch = objectAttributes.TargetBranch;

// MR 标题
var title = objectAttributes.title;
var title = objectAttributes.Title;

var username = rootobject.user.username;
var mergeRequestUrl = objectAttributes.url;
var username = rootobject.User.Username;
var mergeRequestUrl = objectAttributes.Url;

var gitLabMergeRequest = new GitLabMergeRequest
{
Expand Down
Loading

0 comments on commit eb5a946

Please sign in to comment.