Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-568) Set the 'Due date' when closing a milestone if configured to do so #614

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -12,10 +12,12 @@

public int InternalNumber { get; set; }

public string HtmlUrl { get; set; }

Check warning on line 15 in src/GitReleaseManager.Core/Model/Milestone.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Change the type of property 'Milestone.HtmlUrl' from 'string' to 'System.Uri' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1056)

Check warning on line 15 in src/GitReleaseManager.Core/Model/Milestone.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Change the type of property 'Milestone.HtmlUrl' from 'string' to 'System.Uri' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1056)

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
Loading