Skip to content

Commit

Permalink
Make sure to use the creator of a PR instead of the assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
AvdLee committed Mar 6, 2020
1 parent c56c9ff commit a74e050
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Sources/GitBuddyCore/Models/ChangelogItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protocol ChangelogIssue: ChangelogInput { }
protocol ChangelogPullRequest: ChangelogInput { }

extension PullRequest: ChangelogPullRequest {
var username: String? { assignee?.login }
var username: String? { user?.login ?? assignee?.login }
}

extension Issue: ChangelogIssue {
Expand Down
15 changes: 13 additions & 2 deletions Tests/GitBuddyTests/Models/ChangelogItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import XCTest
@testable import GitBuddyCore
import OctoKit

final class ChangelogItemTests: XCTestCase {

Expand All @@ -26,9 +27,19 @@ final class ChangelogItemTests: XCTestCase {

/// It should show the user if possible.
func testUser() {
let input = MockedPullRequest(title: UUID().uuidString, username: "Henk")
let input = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first!
input.htmlURL = nil
let item = ChangelogItem(input: input, closedBy: input)
XCTAssertEqual(item.title, "\(input.title!) via @Henk")
XCTAssertEqual(item.title, "\(input.title!) via @AvdLee")
}

/// It should fallback to the assignee if the user is nil for Pull Requests.
func testAssigneeFallback() {
let input = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first!
input.user = nil
input.htmlURL = nil
let item = ChangelogItem(input: input, closedBy: input)
XCTAssertEqual(item.title, "\(input.title!) via @kairadiagne")
}

/// It should combine the title, number and user.
Expand Down
98 changes: 49 additions & 49 deletions Tests/GitBuddyTests/TestHelpers/PullRequestsJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ let PullRequestsJSON = """
"locked": false,
"title": "Add charset utf-8 to html head",
"user": {
"login": "intitni",
"login": "AvdLee",
"id": 793147,
"node_id": "MDQ6VXNlcjc5MzE0Nw==",
"avatar_url": "https://avatars0.githubusercontent.com/u/793147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/intitni",
"html_url": "https://github.com/intitni",
"followers_url": "https://api.github.com/users/intitni/followers",
"following_url": "https://api.github.com/users/intitni/following{/other_user}",
"gists_url": "https://api.github.com/users/intitni/gists{/gist_id}",
"starred_url": "https://api.github.com/users/intitni/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/intitni/subscriptions",
"organizations_url": "https://api.github.com/users/intitni/orgs",
"repos_url": "https://api.github.com/users/intitni/repos",
"events_url": "https://api.github.com/users/intitni/events{/privacy}",
"received_events_url": "https://api.github.com/users/intitni/received_events",
"url": "https://api.github.com/users/AvdLee",
"html_url": "https://github.com/AvdLee",
"followers_url": "https://api.github.com/users/AvdLee/followers",
"following_url": "https://api.github.com/users/AvdLee/following{/other_user}",
"gists_url": "https://api.github.com/users/AvdLee/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AvdLee/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AvdLee/subscriptions",
"organizations_url": "https://api.github.com/users/AvdLee/orgs",
"repos_url": "https://api.github.com/users/AvdLee/repos",
"events_url": "https://api.github.com/users/AvdLee/events{/privacy}",
"received_events_url": "https://api.github.com/users/AvdLee/received_events",
"type": "User",
"site_admin": false
},
Expand All @@ -49,42 +49,42 @@ let PullRequestsJSON = """
"merged_at": "2020-01-06T12:46:35Z",
"merge_commit_sha": "ada293ab4b12f6423da130edf37217d94ccf8148",
"assignee": {
"login": "AvdLee",
"login": "kairadiagne",
"id": 4329185,
"node_id": "MDQ6VXNlcjQzMjkxODU=",
"avatar_url": "https://avatars2.githubusercontent.com/u/4329185?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AvdLee",
"html_url": "https://github.com/AvdLee",
"followers_url": "https://api.github.com/users/AvdLee/followers",
"following_url": "https://api.github.com/users/AvdLee/following{/other_user}",
"gists_url": "https://api.github.com/users/AvdLee/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AvdLee/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AvdLee/subscriptions",
"organizations_url": "https://api.github.com/users/AvdLee/orgs",
"repos_url": "https://api.github.com/users/AvdLee/repos",
"events_url": "https://api.github.com/users/AvdLee/events{/privacy}",
"received_events_url": "https://api.github.com/users/AvdLee/received_events",
"url": "https://api.github.com/users/kairadiagne",
"html_url": "https://github.com/kairadiagne",
"followers_url": "https://api.github.com/users/kairadiagne/followers",
"following_url": "https://api.github.com/users/kairadiagne/following{/other_user}",
"gists_url": "https://api.github.com/users/kairadiagne/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kairadiagne/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kairadiagne/subscriptions",
"organizations_url": "https://api.github.com/users/kairadiagne/orgs",
"repos_url": "https://api.github.com/users/kairadiagne/repos",
"events_url": "https://api.github.com/users/kairadiagne/events{/privacy}",
"received_events_url": "https://api.github.com/users/kairadiagne/received_events",
"type": "User",
"site_admin": false
},
"assignees": [{
"login": "AvdLee",
"login": "kairadiagne",
"id": 4329185,
"node_id": "MDQ6VXNlcjQzMjkxODU=",
"avatar_url": "https://avatars2.githubusercontent.com/u/4329185?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AvdLee",
"html_url": "https://github.com/AvdLee",
"followers_url": "https://api.github.com/users/AvdLee/followers",
"following_url": "https://api.github.com/users/AvdLee/following{/other_user}",
"gists_url": "https://api.github.com/users/AvdLee/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AvdLee/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AvdLee/subscriptions",
"organizations_url": "https://api.github.com/users/AvdLee/orgs",
"repos_url": "https://api.github.com/users/AvdLee/repos",
"events_url": "https://api.github.com/users/AvdLee/events{/privacy}",
"received_events_url": "https://api.github.com/users/AvdLee/received_events",
"url": "https://api.github.com/users/kairadiagne",
"html_url": "https://github.com/kairadiagne",
"followers_url": "https://api.github.com/users/kairadiagne/followers",
"following_url": "https://api.github.com/users/kairadiagne/following{/other_user}",
"gists_url": "https://api.github.com/users/kairadiagne/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kairadiagne/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kairadiagne/subscriptions",
"organizations_url": "https://api.github.com/users/kairadiagne/orgs",
"repos_url": "https://api.github.com/users/kairadiagne/repos",
"events_url": "https://api.github.com/users/kairadiagne/events{/privacy}",
"received_events_url": "https://api.github.com/users/kairadiagne/received_events",
"type": "User",
"site_admin": false
}],
Expand All @@ -104,26 +104,26 @@ let PullRequestsJSON = """
"comments_url": "https://api.github.com/repos/WeTransfer/Diagnostics/issues/50/comments",
"statuses_url": "https://api.github.com/repos/WeTransfer/Diagnostics/statuses/6c695a40f809fdf80e5522e92b4ded1903a42097",
"head": {
"label": "intitni:charset-in-html",
"label": "AvdLee:charset-in-html",
"ref": "charset-in-html",
"sha": "6c695a40f809fdf80e5522e92b4ded1903a42097",
"user": {
"login": "intitni",
"login": "AvdLee",
"id": 793147,
"node_id": "MDQ6VXNlcjc5MzE0Nw==",
"avatar_url": "https://avatars0.githubusercontent.com/u/793147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/intitni",
"html_url": "https://github.com/intitni",
"followers_url": "https://api.github.com/users/intitni/followers",
"following_url": "https://api.github.com/users/intitni/following{/other_user}",
"gists_url": "https://api.github.com/users/intitni/gists{/gist_id}",
"starred_url": "https://api.github.com/users/intitni/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/intitni/subscriptions",
"organizations_url": "https://api.github.com/users/intitni/orgs",
"repos_url": "https://api.github.com/users/intitni/repos",
"events_url": "https://api.github.com/users/intitni/events{/privacy}",
"received_events_url": "https://api.github.com/users/intitni/received_events",
"url": "https://api.github.com/users/AvdLee",
"html_url": "https://github.com/AvdLee",
"followers_url": "https://api.github.com/users/AvdLee/followers",
"following_url": "https://api.github.com/users/AvdLee/following{/other_user}",
"gists_url": "https://api.github.com/users/AvdLee/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AvdLee/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AvdLee/subscriptions",
"organizations_url": "https://api.github.com/users/AvdLee/orgs",
"repos_url": "https://api.github.com/users/AvdLee/repos",
"events_url": "https://api.github.com/users/AvdLee/events{/privacy}",
"received_events_url": "https://api.github.com/users/AvdLee/received_events",
"type": "User",
"site_admin": false
},
Expand Down

0 comments on commit a74e050

Please sign in to comment.