Commit 306faaa7 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'discussions'

45a2205d test/types: add tests for the data models
92368eb5 data: Add some data for the discussions test from a MR
df2e51d2 data/fetch: add an option to dump the whole content of a query
a245bf17 gitlab: Add a couple of methods to get and create discussions on MRs
8f406421

 types: Add the necessary models to fetch discussion information
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !158
parents 14f2b42b 45a2205d
[
{
"id": "cf0c0f06ce25d48f9228ab0e5eacb1f13d9a5209",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon",
"id": 11,
"name": "Kitware Robot",
"state": "active",
"username": "kwrobot",
"web_url": "https://gitlab.kitware.com/kwrobot"
},
"body": "Basic content checks passed!\n\nBranch-at: 04e94ae667024a62a90179f395bfdc2b35f3efd2 \nAcked-by: @kwrobot",
"created_at": "2016-10-04T15:56:54.015-04:00",
"id": 177359,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": false,
"type": null,
"updated_at": "2016-10-04T15:56:54.015-04:00"
}
]
},
{
"id": "ec35059bf30784083ccdf9f1a929338e6e10ba04",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "+2\n\nDo: merge",
"created_at": "2016-10-04T16:18:35.548-04:00",
"id": 177368,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": false,
"type": null,
"updated_at": "2016-10-04T16:18:35.548-04:00"
}
]
},
{
"id": "1c1eccd9e86c75e56a01d26cfd7d7ee57ad18e0a",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon",
"id": 11,
"name": "Kitware Robot",
"state": "active",
"username": "kwrobot",
"web_url": "https://gitlab.kitware.com/kwrobot"
},
"body": "Branch successfully merged and pushed!",
"created_at": "2016-10-04T16:18:57.466-04:00",
"id": 177369,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": false,
"type": null,
"updated_at": "2016-10-04T16:18:57.466-04:00"
}
]
},
{
"id": "2fb15a0dc8c2293d632a757db20fa95152036ebc",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Mentioned in commit 47d475d8625424bd37efd27f7097354306842b93",
"created_at": "2016-10-04T16:18:57.786-04:00",
"id": 177371,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": true,
"type": null,
"updated_at": "2016-10-04T16:18:57.786-04:00"
}
]
},
{
"id": "e7e5c2688e7c32b8086c223840534bdcbdc1d7af",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon",
"id": 11,
"name": "Kitware Robot",
"state": "active",
"username": "kwrobot",
"web_url": "https://gitlab.kitware.com/kwrobot"
},
"body": "Status changed to merged",
"created_at": "2016-10-04T16:18:57.937-04:00",
"id": 177373,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": true,
"type": null,
"updated_at": "2016-10-04T16:18:57.937-04:00"
}
]
},
{
"id": "397dbd07ac8796e539db624e56ec318453cb3599",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/c6d5328c0ae2a0589a054b18542961e7?s=80&d=identicon",
"id": 12142,
"name": "Simon Chopin",
"state": "active",
"username": "laarmen",
"web_url": "https://gitlab.kitware.com/laarmen"
},
"body": "mentioned in merge request !158",
"created_at": "2019-08-06T14:10:46.934-04:00",
"id": 607465,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": true,
"type": null,
"updated_at": "2019-08-06T14:10:46.936-04:00"
}
]
},
{
"id": "a4d5505b3556eaa45edbe567af7aebc1760dedd7",
"individual_note": false,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Start sample discussion.",
"created_at": "2019-08-07T09:52:52.190-04:00",
"id": 607911,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": true,
"resolved": true,
"resolved_by": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"system": false,
"type": "DiscussionNote",
"updated_at": "2019-08-07T09:52:52.190-04:00"
},
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Comment on sample discussion.",
"created_at": "2019-08-07T09:53:00.074-04:00",
"id": 607912,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": true,
"resolved": true,
"resolved_by": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"system": false,
"type": "DiscussionNote",
"updated_at": "2019-08-07T09:53:00.074-04:00"
},
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Comment and resolve sample discussion.",
"created_at": "2019-08-07T09:53:08.058-04:00",
"id": 607913,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": true,
"resolved": true,
"resolved_by": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"system": false,
"type": "DiscussionNote",
"updated_at": "2019-08-07T09:53:08.058-04:00"
}
]
},
{
"id": "3fc9a701c54f4ec16510ce0d3de71bc3f52b9632",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "resolved all threads",
"created_at": "2019-08-07T09:53:08.398-04:00",
"id": 607914,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": true,
"type": null,
"updated_at": "2019-08-07T09:53:08.401-04:00"
}
]
},
{
"id": "18ea341cb10e952889e277836ba638c6b17ff26c",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Sample note.",
"created_at": "2019-08-29T13:30:19.341-04:00",
"id": 619271,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": false,
"type": null,
"updated_at": "2019-08-29T13:30:19.341-04:00"
}
]
},
{
"id": "9f4998b2308728b95cff52af97019479e1269183",
"individual_note": false,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Start sample review discussion.",
"created_at": "2019-08-29T13:30:56.406-04:00",
"id": 619272,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"position": {
"base_sha": "981262b03fc0149c1677ca51ea47b570e30d6a90",
"head_sha": "04e94ae667024a62a90179f395bfdc2b35f3efd2",
"new_line": 156,
"new_path": "src/gitlab.rs",
"old_line": null,
"old_path": "src/gitlab.rs",
"position_type": "text",
"start_sha": "981262b03fc0149c1677ca51ea47b570e30d6a90"
},
"resolvable": true,
"resolved": true,
"resolved_by": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"system": false,
"type": "DiffNote",
"updated_at": "2019-08-29T13:30:56.406-04:00"
},
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Comment on sample review discussion.",
"created_at": "2019-08-29T13:31:02.993-04:00",
"id": 619273,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"position": {
"base_sha": "981262b03fc0149c1677ca51ea47b570e30d6a90",
"head_sha": "04e94ae667024a62a90179f395bfdc2b35f3efd2",
"new_line": 156,
"new_path": "src/gitlab.rs",
"old_line": null,
"old_path": "src/gitlab.rs",
"position_type": "text",
"start_sha": "981262b03fc0149c1677ca51ea47b570e30d6a90"
},
"resolvable": true,
"resolved": true,
"resolved_by": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"system": false,
"type": "DiffNote",
"updated_at": "2019-08-29T13:31:02.993-04:00"
},
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "Comment and resolve sample review discussion.",
"created_at": "2019-08-29T13:31:17.580-04:00",
"id": 619274,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"position": {
"base_sha": "981262b03fc0149c1677ca51ea47b570e30d6a90",
"head_sha": "04e94ae667024a62a90179f395bfdc2b35f3efd2",
"new_line": 156,
"new_path": "src/gitlab.rs",
"old_line": null,
"old_path": "src/gitlab.rs",
"position_type": "text",
"start_sha": "981262b03fc0149c1677ca51ea47b570e30d6a90"
},
"resolvable": true,
"resolved": true,
"resolved_by": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"system": false,
"type": "DiffNote",
"updated_at": "2019-08-29T13:31:17.580-04:00"
}
]
},
{
"id": "6135399579941bd203787667c16e2a53413af10c",
"individual_note": true,
"notes": [
{
"attachment": null,
"author": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
},
"body": "resolved all threads",
"created_at": "2019-08-29T13:31:17.886-04:00",
"id": 619275,
"noteable_id": 20215,
"noteable_iid": 35,
"noteable_type": "MergeRequest",
"resolvable": false,
"system": true,
"type": null,
"updated_at": "2019-08-29T13:31:17.889-04:00"
}
]
}
]
......@@ -10,16 +10,17 @@ def fetch_from_gitlab(token, endpoint, **kwargs):
return response.json()
def write_result(token, name, endpoint):
def write_result(token, name, endpoint, dumpall=False):
print('Writing out %s...' % name)
result = fetch_from_gitlab(token, endpoint)
if type(result) == list:
result = result[0]
# Remove any keys from the result.
result.pop('private_token', None)
result.pop('runners_token', None)
if type(result.get('identities')) == list:
result['identities'] = []
if not dumpall:
if type(result) == list:
result = result[0]
# Remove any keys from the result.
result.pop('private_token', None)
result.pop('runners_token', None)
if type(result.get('identities')) == list:
result['identities'] = []
with open('%s.json' % name, 'w+') as fout:
json.dump(result, fout, indent = 2, separators=(',', ': '), sort_keys=True)
fout.write('\n')
......@@ -30,6 +31,7 @@ USER = 11 # kwrobot
COMMIT = 'de4ac3cf96cb8a0893be22b03f5171d934f9d392'
ISSUE_ID = 6 # https://gitlab.kitware.com/utils/rust-gitlab/issues/6
MR_ID = 35 # https://gitlab.kitware.com/utils/rust-gitlab/merge_requests/35
MR_DISCUSSION_ID = 158 # https://gitlab.kitware.com/utils/rust-gitlab/merge_requests/35
NOTE_ID = 177359
......@@ -49,5 +51,6 @@ if __name__ == '__main__':
write_result(token, 'merge_request', '/projects/%s/merge_requests/%d' % (REPO, MR_ID))
write_result(token, 'issue_reference', '/projects/%s/merge_requests/%d/closes_issues' % (REPO, MR_ID))
write_result(token, 'note', '/projects/%s/merge_requests/%d/notes' % (REPO, MR_ID))
write_result(token, 'discussion', '/projects/%s/merge_requests/%d/discussions' % (REPO, MR_ID), dumpall=True)
write_result(token, 'award_emoji', '/projects/%s/merge_requests/%d/notes/%d/award_emoji' % (REPO, MR_ID, NOTE_ID))
write_result(token, 'resource_label_event', '/projects/%s/issues/%d/resource_label_events' % (REPO, ISSUE_ID))
......@@ -1005,6 +1005,28 @@ impl Gitlab {
)
}
/// Get the discussions from a merge request.
pub fn merge_request_discussions<I, K, V>(
&self,
project: ProjectId,
merge_request: MergeRequestInternalId,
params: I,
) -> Result<Vec<Discussion>>
where
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: AsRef<str>,
{
self.get_paged_with_param(
&format!(
"projects/{}/merge_requests/{}/discussions",
project, merge_request,
),
params,
)
}
/// Get the notes from a merge request.
pub fn merge_request_notes<I, K, V>(
&self,
......@@ -1196,6 +1218,18 @@ impl Gitlab {
)
}
pub fn create_merge_request_discussion(
&self,
project: ProjectId,
merge_request: MergeRequestInternalId,
content: &str,
) -> Result<Discussion> {
let path = &format!(
"projects/{}/merge_requests/{}/discussions",
project, merge_request
);
self.post_with_param(path, &[("body", content)])
}
/// Create a note on a merge request.
pub fn create_merge_request_note(
&self,
......
......@@ -462,6 +462,63 @@ fn test_read_note() {
assert_eq!(note.noteable_type, NoteType::MergeRequest);
}
#[test]
fn test_read_singlenote_discussion() {
let discussions: Vec<Discussion> = read_test_file("discussion");
let discussion = discussions.iter().find(|x| x.id.value() == "18ea341cb10e952889e277836ba638c6b17ff26c").unwrap();
assert!(discussion.individual_note);
assert_eq!(discussion.notes.len(), 1);
let note = discussion.notes.get(0).unwrap();
assert!(!(note.resolvable));
assert!(note.position.is_none());
assert!(note.note_type.is_none())
}
#[test]
fn test_read_nocode_discussion() {
let discussions: Vec<Discussion> = read_test_file("discussion");
let discussion = discussions.iter().find(|x| x.id.value() == "a4d5505b3556eaa45edbe567af7aebc1760dedd7").unwrap();
assert!(!(discussion.individual_note));
assert_eq!(discussion.notes.len(), 3);
let question = discussion.notes.get(0).unwrap();
let comment = discussion.notes.get(1).unwrap();
assert!(question.resolvable);
assert!(comment.resolvable);
assert!(question.resolved.is_some());
assert!(question.position.is_none());
assert!(comment.position.is_none());
assert_eq!(question.id, NoteId::new(607911));
assert_eq!(comment.id, NoteId::new(607912));
assert_eq!(question.note_type, Some(DiscussionNoteType::DiscussionNote));
assert_eq!(comment.note_type, Some(DiscussionNoteType::DiscussionNote));
}
#[test]
fn test_read_code_discussion() {
let discussions: Vec<Discussion> = read_test_file("discussion");
let discussion = discussions.into_iter().find(|x| x.id.value() == "9f4998b2308728b95cff52af97019479e1269183").unwrap();
assert!(!(discussion.individual_note));
let note = discussion.notes.get(0).unwrap();
assert!(note.resolvable);
assert!(note.resolved.is_some());
assert_eq!(note.author.username, "brad.king");
assert_eq!(note.id, NoteId::new(619272));
assert_eq!(note.note_type, Some(DiscussionNoteType