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

fix(codemagic_app_preview): fix posting comment on GitLab #111

Merged
merged 4 commits into from
Dec 20, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ void main() {
projectId: projectId,
mergeRequestId: pullRequestId,
);
final randomText = DateTime.now().toIso8601String();

// The comment body should also contain special characters to avoid
// https://github.com/nilsreichardt/codemagic-app-preview/pull/111 again.
final randomText = '${DateTime.now().toIso8601String()};&?#=';

final comment = await gitLabApiRepository.postComment(
randomText,
Expand All @@ -98,6 +101,7 @@ void main() {
allComments.contains(comment),
true,
);
expect(comment.body, randomText);
});
});

Expand All @@ -113,7 +117,10 @@ void main() {
mergeRequestId: pullRequestId,
);
const commentId = 1230789237;
final randomText = DateTime.now().toIso8601String();

// The comment body should also contain special characters to avoid
// https://github.com/nilsreichardt/codemagic-app-preview/pull/111 again.
final randomText = '${DateTime.now().toIso8601String()};&?#=';

await gitLabApiRepository.editComment(commentId, randomText);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class GitLabApiRepository implements GitHostRepository {
Future<PostedComment> postComment(
String comment,
) async {
final encodedComment = Uri.encodeComponent(comment);
final response = await httpClient.post(
Uri.parse(
'$_baseUrl/api/v4/projects/$projectId/merge_requests/$mergeRequestId/notes?body=$comment',
'$_baseUrl/api/v4/projects/$projectId/merge_requests/$mergeRequestId/notes?body=$encodedComment',
nilsreichardt marked this conversation as resolved.
Show resolved Hide resolved
),
headers: {
'Authorization': 'Bearer $token',
Expand All @@ -59,9 +60,10 @@ class GitLabApiRepository implements GitHostRepository {
/// Edits an existing comment.
@override
Future<void> editComment(int commentId, String comment) async {
final encodedComment = Uri.encodeComponent(comment);
final response = await httpClient.put(
Uri.parse(
'$_baseUrl/api/v4/projects/$projectId/merge_requests/$mergeRequestId/notes/$commentId?body=$comment',
'$_baseUrl/api/v4/projects/$projectId/merge_requests/$mergeRequestId/notes/$commentId?body=$encodedComment',
),
headers: {
'Authorization': 'Bearer $token',
Expand Down
Loading