0

I want to write a tool for automerging changes from master into feature branches. I use two tools here, a branchtool which creates new feature branches, the users are able to enable or disable automerge for their feature branches and a automergetool which, runs as a service on the server and needs to read this information and run the merge process.

During my research i discovered GitRef.Statuses and "GitStatus"-Class, which "contains the metadata of a service/extension posting a status" (official microsoft description). GitStatus looks very interesting, because i can define own Statuses and set a state on it. The Problem is, i didn't found anything about it - except MS-Pages, which are not very far-reaching. i don't know whether my procedure is correct or not. So how can i use it? My intention is this one:

public Branch AddStatusToBranch(Branch branch) { if (!(branch.GitBranch.Statuses is List<GitStatus> bGitStatuses)) bGitStatuses = new List<GitStatus>(); _status = null; if ((_status = bGitStatuses.Find(s => s.Context.Genre == _genre)) != null) { return branch; } else { _status = new GitStatus() { Context = new GitStatusContext() { Genre = _genre, Name = branch.DisplayName } }; bGitStatuses.Add(_status); branch.GitBranch.Statuses = bGitStatuses; return branch; } } 

Maybe there is another - a simpler - way to transport and save this information (which shall not be lost, just when set through the tool or a pullrequest or deletion of this branch happened).

So how to use GitStatus correct?

Kind Regards Mirko

8
  • How does your tool automatically handle merge conflicts? Commented Nov 7, 2019 at 10:20
  • if there are any merge conflicts the automated merge will be withdrawn and the developer will be informed, that master has changes and merge conflicts appear (maybe there will be a solution in the future to automate that as well) Commented Nov 7, 2019 at 10:29
  • Seems no problem on your script, did you facing error with this script? Or just want a simpler way to configure the GitStatus class and called it? Commented Nov 8, 2019 at 9:19
  • @MerlinLiang-MSFT no, there are no issues with that code example, i want to understand gitstatus correctly, as there is not a really documetation to find. can i use it for my purpose or not? Is there any constellation, which could lead to a reset of GitStatus (like merging in another branch where this is not set and so on)? i need a simple and save way to tell the other tool that automerge is active or not for a specific branch. alternativly we thought about saving a workitem at azure devops to have a save places. Commented Nov 8, 2019 at 9:27
  • 1
    I provide my understanding into below answer, hope it could give you some assistance:-) Commented Nov 8, 2019 at 11:43

1 Answer 1

3

Thanks for the detailed expression in comment.

In fact, you can refer to the relevant Rest api doc to get know more about the GitStatus Class. This GitStatus only available under commit.

Yes, we can give a body to GitStatus like

_status = new GitStatus() { Context = new GitStatusContext() { Genre = _genre, Name = branch.DisplayName } }; 

But, as I know, here you need also specified one necessary property in the body: State. Normally, we define it as:

GitStatusState state 

So, here the basic structure should look like(I just wrote a simple sample):

public static GitStatus GetTestGitStatus(GitStatusState state){ GitStatus myStatus = new GitStatus(); myStatus.Context = GetTestStatusContext(name, genre);//Context myStatus.State = state;//State } 

To specified the value to State, you can also directly use

State = GitStatusState.Succeeded, // GitStatusState.{xxxx}


Since you mentioned in the comment: whether it could be used for personal purpose and be override by others.

Of course, yes, it can be used for customized. You can define any thing with that syntax. Note: There has one limitation, for State value, you must use the one which listed here.

For Status, just consider it as an array. This means it will not be override after you specified one customized status content on it. If there is one new status update here, it will be stored into this "array" in turn, and the new status storage location is always array[0].

So, if you want to use it as telling the other tool that auto merge is active or not for a specific branch, you need concern that the new status which created by other system actions would cover the location of the one you created previously. I suggest you'd better store the status id after you create it, as the identifier of other tools to know the corresponding status.

Update: Here the other actions not just limited to your customized action, it also include some system actions, including builds, tests, commits and etc.

Sign up to request clarification or add additional context in comments.

10 Comments

thnaks for you explanation, i will give it a try and reply after evaluating it. :)
@Mirko, hoping your good news. In addition, in my answer, it was a bit confusing about the usage of state and status. Has been corrected, you can view the edited answer. Hope not mislead you:-)
@Mirko, which part are you still facing the confusing?
@Mirko, as my answered mentioned, it would be override by other action. And this action include our backend script. I just checked our script again, it would create a gitstatus message when the new commit exists. This means, when you merge one branch into the other, the system will automatically create a new gitstatus message into array[0] to override the previous one, since the system detect out the new commit. That's why I suggest you remember the status id.
@Exar666Kun. It's okay. My fault that did not mentioned these automatically backend actions. Would update this into answer.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.