Skip to content

Commit 5ca12e8

Browse files
fierc3pascalbergerCopilot
authored
Add Title and Description properties to AzureDevOpsPullRequest (#543)
Co-authored-by: Pascal Berger <pascal.berger@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent d65d6c6 commit 5ca12e8

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/Cake.AzureDevOps.Tests/Fakes/FakeAllSetGitClientFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public override GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCre
2727
SourceRefName = "foo",
2828
TargetRefName = "master",
2929
CodeReviewId = 123,
30+
Title = "Add feature X",
31+
Description = "This pull request adds feature X.",
3032
LastMergeSourceCommit = new GitCommitRef { CommitId = "4a92b977" },
3133
LastMergeTargetCommit = new GitCommitRef { CommitId = "78a3c113" },
3234
});
@@ -55,6 +57,8 @@ public override GitHttpClient CreateGitClient(Uri collectionUrl, IAzureDevOpsCre
5557
SourceRefName = sc.SourceRefName,
5658
TargetRefName = "master",
5759
CodeReviewId = 123,
60+
Title = "Add feature X",
61+
Description = "This pull request adds feature X.",
5862
LastMergeSourceCommit = new GitCommitRef { CommitId = "4a92b977" },
5963
LastMergeTargetCommit = new GitCommitRef { CommitId = "78a3c113" },
6064
},

src/Cake.AzureDevOps.Tests/Repos/PullRequest/AzureDevOpsPullRequestTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public void Should_Return_Valid_AzureDevOps_Pull_Request_By_Id()
131131
pullRequest.ProjectName.ShouldBe("MyTeamProject");
132132
pullRequest.SourceRefName.ShouldBe("foo");
133133
pullRequest.TargetRefName.ShouldBe("master");
134+
pullRequest.Title.ShouldBe("Add feature X");
135+
pullRequest.Description.ShouldBe("This pull request adds feature X.");
134136
pullRequest.LastSourceCommitId.ShouldBe("4a92b977");
135137
pullRequest.LastTargetCommitId.ShouldBe("78a3c113");
136138
}
@@ -155,6 +157,8 @@ public void Should_Return_Valid_Azure_DevOps_Pull_Request_By_Id()
155157
pullRequest.ProjectName.ShouldBe("MyProject");
156158
pullRequest.SourceRefName.ShouldBe("foo");
157159
pullRequest.TargetRefName.ShouldBe("master");
160+
pullRequest.Title.ShouldBe("Add feature X");
161+
pullRequest.Description.ShouldBe("This pull request adds feature X.");
158162
pullRequest.LastSourceCommitId.ShouldBe("4a92b977");
159163
pullRequest.LastTargetCommitId.ShouldBe("78a3c113");
160164
}
@@ -179,6 +183,8 @@ public void Should_Return_Valid_AzureDevOps_Pull_Request_By_Source_Branch()
179183
pullRequest.ProjectName.ShouldBe("MyTeamProject");
180184
pullRequest.SourceRefName.ShouldBe("feature");
181185
pullRequest.TargetRefName.ShouldBe("master");
186+
pullRequest.Title.ShouldBe("Add feature X");
187+
pullRequest.Description.ShouldBe("This pull request adds feature X.");
182188
pullRequest.LastSourceCommitId.ShouldBe("4a92b977");
183189
pullRequest.LastTargetCommitId.ShouldBe("78a3c113");
184190
}
@@ -203,6 +209,8 @@ public void Should_Return_Valid_Azure_DevOps_Pull_Request_By_Source_Branch()
203209
pullRequest.ProjectName.ShouldBe("MyProject");
204210
pullRequest.SourceRefName.ShouldBe("feature");
205211
pullRequest.TargetRefName.ShouldBe("master");
212+
pullRequest.Title.ShouldBe("Add feature X");
213+
pullRequest.Description.ShouldBe("This pull request adds feature X.");
206214
pullRequest.LastSourceCommitId.ShouldBe("4a92b977");
207215
pullRequest.LastTargetCommitId.ShouldBe("78a3c113");
208216
}
@@ -232,6 +240,8 @@ public void Should_Return_Null_AzureDevOps_Pull_Request_By_Id()
232240
pullRequest.CodeReviewId.ShouldBe(0);
233241
pullRequest.SourceRefName.ShouldBeEmpty();
234242
pullRequest.TargetRefName.ShouldBeEmpty();
243+
pullRequest.Title.ShouldBeEmpty();
244+
pullRequest.Description.ShouldBeEmpty();
235245
pullRequest.LastSourceCommitId.ShouldBeEmpty();
236246
pullRequest.LastTargetCommitId.ShouldBeEmpty();
237247
}
@@ -261,6 +271,8 @@ public void Should_Return_Null_Azure_DevOps_Pull_Request_By_Id()
261271
pullRequest.CodeReviewId.ShouldBe(0);
262272
pullRequest.SourceRefName.ShouldBeEmpty();
263273
pullRequest.TargetRefName.ShouldBeEmpty();
274+
pullRequest.Title.ShouldBeEmpty();
275+
pullRequest.Description.ShouldBeEmpty();
264276
pullRequest.LastSourceCommitId.ShouldBeEmpty();
265277
pullRequest.LastTargetCommitId.ShouldBeEmpty();
266278
}
@@ -290,6 +302,8 @@ public void Should_Return_Null_AzureDevOps_Pull_Request_By_Branch()
290302
pullRequest.CodeReviewId.ShouldBe(0);
291303
pullRequest.SourceRefName.ShouldBeEmpty();
292304
pullRequest.TargetRefName.ShouldBeEmpty();
305+
pullRequest.Title.ShouldBeEmpty();
306+
pullRequest.Description.ShouldBeEmpty();
293307
pullRequest.LastSourceCommitId.ShouldBeEmpty();
294308
pullRequest.LastTargetCommitId.ShouldBeEmpty();
295309
}
@@ -319,6 +333,8 @@ public void Should_Return_Null_Azure_DevOps_Pull_Request_By_Branch()
319333
pullRequest.CodeReviewId.ShouldBe(0);
320334
pullRequest.SourceRefName.ShouldBeEmpty();
321335
pullRequest.TargetRefName.ShouldBeEmpty();
336+
pullRequest.Title.ShouldBeEmpty();
337+
pullRequest.Description.ShouldBeEmpty();
322338
pullRequest.LastSourceCommitId.ShouldBeEmpty();
323339
pullRequest.LastTargetCommitId.ShouldBeEmpty();
324340
}

src/Cake.AzureDevOps/Repos/PullRequest/AzureDevOpsPullRequest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ internal AzureDevOpsPullRequest(ICakeLog log, AzureDevOpsPullRequestSettings set
182182
/// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
183183
public int PullRequestId => this.ValidatePullRequest() ? this.pullRequest.PullRequestId : 0;
184184

185+
/// <summary>
186+
/// Gets the title of the pull request.
187+
/// Returns <see cref="string.Empty"/> if no pull request could be found and
188+
/// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>false</c>.
189+
/// </summary>
190+
/// <exception cref="AzureDevOpsPullRequestNotFoundException">If pull request could not be found and
191+
/// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
192+
public string Title => this.ValidatePullRequest() ? (this.pullRequest.Title ?? string.Empty) : string.Empty;
193+
194+
/// <summary>
195+
/// Gets the description of the pull request.
196+
/// Returns <see cref="string.Empty"/> if no pull request could be found and
197+
/// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>false</c>.
198+
/// </summary>
199+
/// <exception cref="AzureDevOpsPullRequestNotFoundException">If pull request could not be found and
200+
/// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception>
201+
public string Description => this.ValidatePullRequest() ? (this.pullRequest.Description ?? string.Empty) : string.Empty;
202+
185203
/// <summary>
186204
/// Gets if the pull request is in draft mode.
187205
/// Returns <see cref="AzureDevOpsPullRequestState.NotSet"/> if no pull request could be found and

0 commit comments

Comments
 (0)