Skip to content

Commit

Permalink
(GitToolsGH-568) Set the 'Due date' when closing a milestone if confi…
Browse files Browse the repository at this point in the history
…gured to do so
  • Loading branch information
Jericho committed Jul 27, 2024
1 parent f753585 commit d9e98bd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/GitReleaseManager.Core/Configuration/CloseConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ public sealed class CloseConfig
[Sample(":tada: This issue has been resolved in version {milestone} :tada:\n\nThe release is available on:\n\n- [NuGet package(@{milestone})](https://nuget.org/packages/{repository}/{milestone})\n- [GitHub release](https://github.com/{owner}/{repository}/releases/tag/{milestone})\n\nYour **[GitReleaseManager](https://github.com/GitTools/GitReleaseManager)** bot :package::rocket:")]
[YamlMember(Alias = "issue-comment", ScalarStyle = YamlDotNet.Core.ScalarStyle.Literal)]
public string IssueCommentFormat { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the due date should be set when closing the milestone.
/// </summary>
[Description("Whether to set the due date when closing the milestone.")]
[YamlMember(Alias = "set-due-date")]
public bool SetDueDate { get; set; }
}
}
1 change: 1 addition & 0 deletions src/GitReleaseManager.Core/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Config()
{
IssueComments = false,
IssueCommentFormat = ISSUE_COMMENT_FORMAT,
SetDueDate = false, // by default, do not set the due date to match previous behavior
};

DefaultBranch = "master";
Expand Down
2 changes: 2 additions & 0 deletions src/GitReleaseManager.Core/Model/Milestone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public sealed class Milestone
public string Url { get; set; }

public Version Version { get; set; }

public DateTimeOffset? DueOn { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Core/Provider/GitHubProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Task SetMilestoneStateAsync(string owner, string repository, Milestone mi
{
return ExecuteAsync(async () =>
{
var update = new MilestoneUpdate { State = (Octokit.ItemState)itemState };
var update = new MilestoneUpdate { State = (Octokit.ItemState)itemState, DueOn = milestone.DueOn };
await _gitHubClient.Issue.Milestone.Update(owner, repository, milestone.PublicNumber, update).ConfigureAwait(false);
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/GitReleaseManager.Core/Provider/GitLabProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ public Task SetMilestoneStateAsync(string owner, string repository, Milestone mi
}
else if (itemState == ItemState.Closed)
{
if (milestone.DueOn.HasValue)
{
mileStoneClient.Update(milestone.InternalNumber, new MilestoneUpdate { DueDate = milestone.DueOn.Value.ToString("o", CultureInfo.InvariantCulture) });
}
mileStoneClient.Close(milestone.InternalNumber);
}
Expand Down
3 changes: 3 additions & 0 deletions src/GitReleaseManager.Core/VcsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ public async Task CloseMilestoneAsync(string owner, string repository, string mi
_logger.Verbose("Finding open milestone with title '{Title}' on '{Owner}/{Repository}'", milestoneTitle, owner, repository);
var milestone = await _vcsProvider.GetMilestoneAsync(owner, repository, milestoneTitle, ItemStateFilter.Open).ConfigureAwait(false);

// Set the due date only if configured to do so
milestone.DueOn = _configuration.Close.SetDueDate ? DateTimeOffset.UtcNow : (DateTimeOffset?)null;

_logger.Verbose("Closing milestone '{Title}' on '{Owner}/{Repository}'", milestoneTitle, owner, repository);
await _vcsProvider.SetMilestoneStateAsync(owner, repository, milestone, ItemState.Closed).ConfigureAwait(false);

Expand Down

0 comments on commit d9e98bd

Please sign in to comment.