From 1e63f582d69a2c78335af532171e2fb2749251a6 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 28 Sep 2024 02:04:14 -0800 Subject: [PATCH] add some more fields to repo, and structure for organization (#191) * add some more fields to repo, and structure for organization * add API to read a user's starred repositories * add test for repo updates * test org decoding; remove some invalid properties * remove duplicate methods to fetch starred repos * add Organization to all necessary targets * use local fork of RequestKit * fix tests * fix spm tool version * put back RequestKit dep * fix spm tool version again * fix lint issues --------- Co-authored-by: Andrew McKnight --- OctoKit.xcodeproj/project.pbxproj | 18 ++ OctoKit/Organization.swift | 25 +++ OctoKit/Repositories.swift | 14 +- Package.swift | 2 +- Tests/OctoKitTests/Fixtures/forked_repo.json | 178 +++++++++++++++++++ Tests/OctoKitTests/Fixtures/repo.json | 66 ++++++- Tests/OctoKitTests/RepositoryTests.swift | 31 +++- 7 files changed, 329 insertions(+), 5 deletions(-) create mode 100644 OctoKit/Organization.swift create mode 100644 Tests/OctoKitTests/Fixtures/forked_repo.json diff --git a/OctoKit.xcodeproj/project.pbxproj b/OctoKit.xcodeproj/project.pbxproj index 6540ac8b..98543bab 100644 --- a/OctoKit.xcodeproj/project.pbxproj +++ b/OctoKit.xcodeproj/project.pbxproj @@ -176,6 +176,13 @@ 721F73E929889A040064B11A /* latest_release.json in Resources */ = {isa = PBXBuildFile; fileRef = 721F73E829889A040064B11A /* latest_release.json */; }; 721F73EA29889A040064B11A /* latest_release.json in Resources */ = {isa = PBXBuildFile; fileRef = 721F73E829889A040064B11A /* latest_release.json */; }; 721F73EB29889A040064B11A /* latest_release.json in Resources */ = {isa = PBXBuildFile; fileRef = 721F73E829889A040064B11A /* latest_release.json */; }; + 84B89D012C814DBC00273C68 /* Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B89D002C814DBC00273C68 /* Organization.swift */; }; + 84B89D032C814DE400273C68 /* forked_repo.json in Resources */ = {isa = PBXBuildFile; fileRef = 84B89D022C814DE400273C68 /* forked_repo.json */; }; + 84B89D042C814DED00273C68 /* forked_repo.json in Resources */ = {isa = PBXBuildFile; fileRef = 84B89D022C814DE400273C68 /* forked_repo.json */; }; + 84B89D052C814DEE00273C68 /* forked_repo.json in Resources */ = {isa = PBXBuildFile; fileRef = 84B89D022C814DE400273C68 /* forked_repo.json */; }; + 84B89D0A2C81587100273C68 /* Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B89D002C814DBC00273C68 /* Organization.swift */; }; + 84B89D0B2C81587100273C68 /* Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B89D002C814DBC00273C68 /* Organization.swift */; }; + 84B89D0C2C81587200273C68 /* Organization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B89D002C814DBC00273C68 /* Organization.swift */; }; 9D9ADDDF23EEFD4A000AC34D /* ReviewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9ADDDE23EEFD4A000AC34D /* ReviewTests.swift */; }; 9D9ADDE123EEFDE0000AC34D /* Review.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9ADDE023EEFDE0000AC34D /* Review.swift */; }; BF8C719220F02AC04EF3D137 /* PullRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF8C76EB002802C14A08F63E /* PullRequestTests.swift */; }; @@ -333,6 +340,8 @@ 665D5D5E24A639D70045E3B4 /* statuses.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = statuses.json; path = Fixtures/statuses.json; sourceTree = ""; }; 665D5D5F24A639D70045E3B4 /* status.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = status.json; path = Fixtures/status.json; sourceTree = ""; }; 721F73E829889A040064B11A /* latest_release.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = latest_release.json; path = Fixtures/latest_release.json; sourceTree = ""; }; + 84B89D002C814DBC00273C68 /* Organization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Organization.swift; sourceTree = ""; }; + 84B89D022C814DE400273C68 /* forked_repo.json */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = text.json; name = forked_repo.json; path = Fixtures/forked_repo.json; sourceTree = ""; }; 9D9ADDDE23EEFD4A000AC34D /* ReviewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewTests.swift; sourceTree = ""; }; 9D9ADDE023EEFDE0000AC34D /* Review.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Review.swift; sourceTree = ""; }; BF8C72B985869B84F46B4E9D /* Parameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parameters.swift; sourceTree = ""; }; @@ -454,6 +463,7 @@ children = ( 721F73E829889A040064B11A /* latest_release.json */, 03CCD2512453A9AA007D5CB3 /* users.json */, + 84B89D022C814DE400273C68 /* forked_repo.json */, 515337F92252A0410024544D /* gist.json */, 515337F522529E7B0024544D /* gists.json */, 5090ED7123E483820062C763 /* issue_comment.json */, @@ -486,6 +496,7 @@ isa = PBXGroup; children = ( 239BE7CD1B8C47A100D2CE22 /* OctoKit.h */, + 84B89D002C814DBC00273C68 /* Organization.swift */, 23B267851BDDD756003887E3 /* Configuration.swift */, 515337C3225179FB0024544D /* File.swift */, E7EE59DB1BE119110012E3D2 /* Follow.swift */, @@ -826,6 +837,7 @@ 234F4BE01BDDE44600A58EF7 /* user_mietzmithut.json in Resources */, 23EA61AB25EAE31A001B0964 /* reviews.json in Resources */, 23EA61AE25EAE31A001B0964 /* releases.json in Resources */, + 84B89D032C814DE400273C68 /* forked_repo.json in Resources */, 515337F622529E7B0024544D /* gists.json in Resources */, 721F73E929889A040064B11A /* latest_release.json in Resources */, 23EA61B125EAE31A001B0964 /* pull_request.json in Resources */, @@ -874,6 +886,7 @@ 23F6434C1C7AEF6C000427B3 /* user_mietzmithut.json in Resources */, 23EA61AC25EAE31A001B0964 /* reviews.json in Resources */, 23EA61AF25EAE31A001B0964 /* releases.json in Resources */, + 84B89D042C814DED00273C68 /* forked_repo.json in Resources */, 515337F722529E7B0024544D /* gists.json in Resources */, 721F73EA29889A040064B11A /* latest_release.json in Resources */, 23EA61B225EAE31A001B0964 /* pull_request.json in Resources */, @@ -914,6 +927,7 @@ 23F6434D1C7AEF6D000427B3 /* user_mietzmithut.json in Resources */, 23EA61AD25EAE31A001B0964 /* reviews.json in Resources */, 23EA61B025EAE31A001B0964 /* releases.json in Resources */, + 84B89D052C814DEE00273C68 /* forked_repo.json in Resources */, 515337F822529E7B0024544D /* gists.json in Resources */, 721F73EB29889A040064B11A /* latest_release.json in Resources */, 23EA61B325EAE31A001B0964 /* pull_request.json in Resources */, @@ -978,6 +992,7 @@ 23B2678D1BDDD756003887E3 /* Repositories.swift in Sources */, 5090ED7423E48AA80062C763 /* Releases.swift in Sources */, F8711EA21BFCAE9F005DDACA /* Time.swift in Sources */, + 84B89D012C814DBC00273C68 /* Organization.swift in Sources */, 515337C4225179FB0024544D /* File.swift in Sources */, 515337C2225166600024544D /* Gist.swift in Sources */, 23B2678C1BDDD756003887E3 /* PublicKey.swift in Sources */, @@ -1008,6 +1023,7 @@ 23B2F9C125B1DF6F000A8CE1 /* Review.swift in Sources */, 23CAF2A21C7AB6BE005011C4 /* Configuration.swift in Sources */, 50AFBB1E23EAC89E004D30A8 /* Releases.swift in Sources */, + 84B89D0A2C81587100273C68 /* Organization.swift in Sources */, 23CAF2B71C7AB6EB005011C4 /* Time.swift in Sources */, 23CAF2B41C7AB6D4005011C4 /* Stars.swift in Sources */, 23CAF2AB1C7AB6C9005011C4 /* PublicKey.swift in Sources */, @@ -1064,6 +1080,7 @@ 23B2F9C925B1DF70000A8CE1 /* Review.swift in Sources */, 23CAF2A31C7AB6BF005011C4 /* Configuration.swift in Sources */, 50AFBB1F23EAC89F004D30A8 /* Releases.swift in Sources */, + 84B89D0B2C81587100273C68 /* Organization.swift in Sources */, 23CAF2B81C7AB6EB005011C4 /* Time.swift in Sources */, 23CAF2B51C7AB6D5005011C4 /* Stars.swift in Sources */, 23CAF2AC1C7AB6CA005011C4 /* PublicKey.swift in Sources */, @@ -1120,6 +1137,7 @@ 23B2F9CA25B1DF70000A8CE1 /* Review.swift in Sources */, 23CAF2A41C7AB6BF005011C4 /* Configuration.swift in Sources */, 50AFBB2023EAC8A0004D30A8 /* Releases.swift in Sources */, + 84B89D0C2C81587200273C68 /* Organization.swift in Sources */, 23CAF2B91C7AB6EC005011C4 /* Time.swift in Sources */, 23CAF2B61C7AB6D5005011C4 /* Stars.swift in Sources */, 23CAF2AD1C7AB6CA005011C4 /* PublicKey.swift in Sources */, diff --git a/OctoKit/Organization.swift b/OctoKit/Organization.swift new file mode 100644 index 00000000..c79cada7 --- /dev/null +++ b/OctoKit/Organization.swift @@ -0,0 +1,25 @@ +import Foundation + +open class Organization: Codable { + public let login: String + public let id: Int + public let node_id: String + public let avatar_url: String + public let url: String + public let html_url: String + public let repos_url: String + public let events_url: String + public let type: String + + enum CodingKeys: String, CodingKey { + case login + case id + case node_id + case avatar_url + case url + case html_url + case repos_url + case events_url + case type + } +} diff --git a/OctoKit/Repositories.swift b/OctoKit/Repositories.swift index 93e9c86a..3aa87c38 100644 --- a/OctoKit/Repositories.swift +++ b/OctoKit/Repositories.swift @@ -21,6 +21,10 @@ open class Repository: Codable { open private(set) var size: Int? open var lastPush: Date? open var stargazersCount: Int? + open var hasWiki: Bool? + open var language: String? + open var organization: Organization? + open var parent: Repository? public init(id: Int = -1, owner: User = User(), @@ -35,7 +39,9 @@ open class Repository: Codable { htmlURL: String? = nil, size: Int? = -1, lastPush: Date? = nil, - stargazersCount: Int? = nil) { + stargazersCount: Int? = nil, + hasWiki: Bool = false, + language: String? = nil) { self.id = id self.owner = owner self.name = name @@ -50,6 +56,8 @@ open class Repository: Codable { self.size = size self.lastPush = lastPush self.stargazersCount = stargazersCount + self.hasWiki = hasWiki + self.language = language } enum CodingKeys: String, CodingKey { @@ -67,6 +75,10 @@ open class Repository: Codable { case size case lastPush = "pushed_at" case stargazersCount = "stargazers_count" + case hasWiki = "has_wiki" + case language + case organization + case parent } } diff --git a/Package.swift b/Package.swift index 7ff4c2ce..5daafd41 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.5.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/Tests/OctoKitTests/Fixtures/forked_repo.json b/Tests/OctoKitTests/Fixtures/forked_repo.json new file mode 100644 index 00000000..ecc21db6 --- /dev/null +++ b/Tests/OctoKitTests/Fixtures/forked_repo.json @@ -0,0 +1,178 @@ +{ + "archive_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/{archive_format}{\/ref}", + "assignees_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/assignees{\/user}", + "blobs_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/git\/blobs{\/sha}", + "branches_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/branches{\/branch}", + "clone_url" : "https:\/\/github.com\/mietzmithut\/TestFork.git", + "collaborators_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/collaborators{\/collaborator}", + "comments_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/comments{\/number}", + "commits_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/commits{\/sha}", + "compare_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/compare\/{base}...{head}", + "contents_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/contents\/{+path}", + "contributors_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/contributors", + "created_at" : "2013-06-20T17:05:03Z", + "default_branch" : "master", + "description" : "", + "downloads_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/downloads", + "events_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/events", + "fork" : true, + "parent": { + "archive_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/{archive_format}{\/ref}", + "assignees_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/assignees{\/user}", + "blobs_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/git\/blobs{\/sha}", + "branches_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/branches{\/branch}", + "clone_url" : "https:\/\/github.com\/mietzmithut\/Test.git", + "collaborators_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/collaborators{\/collaborator}", + "comments_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/comments{\/number}", + "commits_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/commits{\/sha}", + "compare_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/compare\/{base}...{head}", + "contents_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/contents\/{+path}", + "contributors_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/contributors", + "created_at" : "2013-06-20T17:05:03Z", + "default_branch" : "master", + "description" : "", + "downloads_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/downloads", + "events_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/events", + "fork" : false, + "forks" : 0, + "forks_count" : 0, + "forks_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/forks", + "full_name" : "mietzmithut\/Test", + "git_commits_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/git\/commits{\/sha}", + "git_refs_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/git\/refs{\/sha}", + "git_tags_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/git\/tags{\/sha}", + "git_url" : "git:\/\/github.com\/mietzmithut\/Test.git", + "has_downloads" : true, + "has_issues" : true, + "has_pages" : false, + "has_wiki" : true, + "homepage" : null, + "hooks_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/hooks", + "html_url" : "https:\/\/github.com\/mietzmithut\/Test", + "id" : 10824973, + "issue_comment_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/issues\/comments\/{number}", + "issue_events_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/issues\/events{\/number}", + "issues_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/issues{\/number}", + "keys_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/keys{\/key_id}", + "labels_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/labels{\/name}", + "language" : "Ruby", + "languages_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/languages", + "merges_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/merges", + "milestones_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/milestones{\/number}", + "mirror_url" : null, + "name" : "Test", + "network_count" : 0, + "notifications_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/notifications{?since,all,participating}", + "open_issues" : 0, + "open_issues_count" : 0, + "owner" : { + "avatar_url" : "https:\/\/avatars.githubusercontent.com\/u\/4672699?v=3", + "events_url" : "https:\/\/api.github.com\/users\/mietzmithut\/events{\/privacy}", + "followers_url" : "https:\/\/api.github.com\/users\/mietzmithut\/followers", + "following_url" : "https:\/\/api.github.com\/users\/mietzmithut\/following{\/other_user}", + "gists_url" : "https:\/\/api.github.com\/users\/mietzmithut\/gists{\/gist_id}", + "gravatar_id" : "", + "html_url" : "https:\/\/github.com\/mietzmithut", + "id" : 4672699, + "login" : "mietzmithut", + "organizations_url" : "https:\/\/api.github.com\/users\/mietzmithut\/orgs", + "received_events_url" : "https:\/\/api.github.com\/users\/mietzmithut\/received_events", + "repos_url" : "https:\/\/api.github.com\/users\/mietzmithut\/repos", + "site_admin" : false, + "starred_url" : "https:\/\/api.github.com\/users\/mietzmithut\/starred{\/owner}{\/repo}", + "subscriptions_url" : "https:\/\/api.github.com\/users\/mietzmithut\/subscriptions", + "type" : "User", + "url" : "https:\/\/api.github.com\/users\/mietzmithut" + }, + "private" : false, + "pulls_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/pulls{\/number}", + "pushed_at" : "2013-06-20T20:04:46Z", + "releases_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/releases{\/id}", + "size" : 132, + "ssh_url" : "git@github.com:mietzmithut\/Test.git", + "stargazers_count" : 0, + "stargazers_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/stargazers", + "statuses_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/statuses\/{sha}", + "subscribers_count" : 2, + "subscribers_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/subscribers", + "subscription_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/subscription", + "svn_url" : "https:\/\/github.com\/mietzmithut\/Test", + "tags_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/tags", + "teams_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/teams", + "trees_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/git\/trees{\/sha}", + "updated_at" : "2014-06-13T21:10:35Z", + "url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test", + "watchers" : 0, + "watchers_count" : 0 + }, + "forks" : 0, + "forks_count" : 0, + "forks_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/forks", + "full_name" : "mietzmithut\/TestFork", + "git_commits_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/git\/commits{\/sha}", + "git_refs_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/git\/refs{\/sha}", + "git_tags_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/git\/tags{\/sha}", + "git_url" : "git:\/\/github.com\/mietzmithut\/TestFork.git", + "has_downloads" : true, + "has_issues" : true, + "has_pages" : false, + "has_wiki" : false, + "homepage" : null, + "hooks_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/hooks", + "html_url" : "https:\/\/github.com\/mietzmithut\/TestFork", + "id" : 10824974, + "issue_comment_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/issues\/comments\/{number}", + "issue_events_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/issues\/events{\/number}", + "issues_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/issues{\/number}", + "keys_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/keys{\/key_id}", + "labels_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/labels{\/name}", + "language" : "Ruby", + "languages_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/languages", + "merges_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/merges", + "milestones_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/milestones{\/number}", + "mirror_url" : null, + "name" : "TestFork", + "network_count" : 0, + "notifications_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/notifications{?since,all,participating}", + "open_issues" : 0, + "open_issues_count" : 0, + "owner" : { + "avatar_url" : "https:\/\/avatars.githubusercontent.com\/u\/4672699?v=3", + "events_url" : "https:\/\/api.github.com\/users\/mietzmithut\/events{\/privacy}", + "followers_url" : "https:\/\/api.github.com\/users\/mietzmithut\/followers", + "following_url" : "https:\/\/api.github.com\/users\/mietzmithut\/following{\/other_user}", + "gists_url" : "https:\/\/api.github.com\/users\/mietzmithut\/gists{\/gist_id}", + "gravatar_id" : "", + "html_url" : "https:\/\/github.com\/mietzmithut", + "id" : 4672699, + "login" : "mietzmithut", + "organizations_url" : "https:\/\/api.github.com\/users\/mietzmithut\/orgs", + "received_events_url" : "https:\/\/api.github.com\/users\/mietzmithut\/received_events", + "repos_url" : "https:\/\/api.github.com\/users\/mietzmithut\/repos", + "site_admin" : false, + "starred_url" : "https:\/\/api.github.com\/users\/mietzmithut\/starred{\/owner}{\/repo}", + "subscriptions_url" : "https:\/\/api.github.com\/users\/mietzmithut\/subscriptions", + "type" : "User", + "url" : "https:\/\/api.github.com\/users\/mietzmithut" + }, + "private" : false, + "pulls_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/pulls{\/number}", + "pushed_at" : "2013-06-20T20:04:46Z", + "releases_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/releases{\/id}", + "size" : 132, + "ssh_url" : "git@github.com:mietzmithut\/TestFork.git", + "stargazers_count" : 0, + "stargazers_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/stargazers", + "statuses_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/statuses\/{sha}", + "subscribers_count" : 2, + "subscribers_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/subscribers", + "subscription_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/subscription", + "svn_url" : "https:\/\/github.com\/mietzmithut\/TestFork", + "tags_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/tags", + "teams_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/teams", + "trees_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork\/git\/trees{\/sha}", + "updated_at" : "2014-06-13T21:10:35Z", + "url" : "https:\/\/api.github.com\/repos\/mietzmithut\/TestFork", + "watchers" : 0, + "watchers_count" : 0 +} diff --git a/Tests/OctoKitTests/Fixtures/repo.json b/Tests/OctoKitTests/Fixtures/repo.json index b8d02320..b8f14ed7 100644 --- a/Tests/OctoKitTests/Fixtures/repo.json +++ b/Tests/OctoKitTests/Fixtures/repo.json @@ -47,6 +47,70 @@ "notifications_url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test\/notifications{?since,all,participating}", "open_issues" : 0, "open_issues_count" : 0, + "organization": { + "login": "github", + "id": 1, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", + "url": "https://api.github.com/orgs/github", + "repos_url": "https://api.github.com/orgs/github/repos", + "events_url": "https://api.github.com/orgs/github/events", + "hooks_url": "https://api.github.com/orgs/github/hooks", + "issues_url": "https://api.github.com/orgs/github/issues", + "members_url": "https://api.github.com/orgs/github/members{/member}", + "public_members_url": "https://api.github.com/orgs/github/public_members{/member}", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "description": "A great organization", + "name": "github", + "company": "GitHub", + "blog": "https://github.com/blog", + "location": "San Francisco", + "email": "octocat@github.com", + "twitter_username": "github", + "is_verified": true, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 2, + "public_gists": 1, + "followers": 20, + "following": 0, + "html_url": "https://github.com/octocat", + "created_at": "2008-01-14T04:33:35Z", + "type": "Organization", + "total_private_repos": 100, + "owned_private_repos": 100, + "private_gists": 81, + "disk_usage": 10000, + "collaborators": 8, + "billing_email": "mona@github.com", + "plan": { + "name": "Medium", + "space": 400, + "private_repos": 20, + "filled_seats": 4, + "seats": 5 + }, + "default_repository_permission": "read", + "members_can_create_repositories": true, + "two_factor_requirement_enabled": true, + "members_allowed_repository_creation_type": "all", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "members_can_fork_private_repositories": false, + "web_commit_signoff_required": false, + "updated_at": "2014-03-03T18:58:10Z", + "dependency_graph_enabled_for_new_repositories": false, + "dependabot_alerts_enabled_for_new_repositories": false, + "dependabot_security_updates_enabled_for_new_repositories": false, + "advanced_security_enabled_for_new_repositories": false, + "secret_scanning_enabled_for_new_repositories": false, + "secret_scanning_push_protection_enabled_for_new_repositories": false, + "secret_scanning_push_protection_custom_link": "https://github.com/octo-org/octo-repo/blob/main/im-blocked.md", + "secret_scanning_push_protection_custom_link_enabled": false + }, "owner" : { "avatar_url" : "https:\/\/avatars.githubusercontent.com\/u\/4672699?v=3", "events_url" : "https:\/\/api.github.com\/users\/mietzmithut\/events{\/privacy}", @@ -86,4 +150,4 @@ "url" : "https:\/\/api.github.com\/repos\/mietzmithut\/Test", "watchers" : 0, "watchers_count" : 0 -} \ No newline at end of file +} diff --git a/Tests/OctoKitTests/RepositoryTests.swift b/Tests/OctoKitTests/RepositoryTests.swift index e95a12ad..28d2fb20 100644 --- a/Tests/OctoKitTests/RepositoryTests.swift +++ b/Tests/OctoKitTests/RepositoryTests.swift @@ -318,7 +318,7 @@ class RepositoryTests: XCTestCase { // MARK: Model Tests - func testUserParsingFullRepository() { + func testUserParsingFullRepository() throws { let subject = Helper.codableFromFile("repo", type: Repository.self) XCTAssertEqual(subject.owner.login, "mietzmithut") XCTAssertEqual(subject.owner.id, 4_672_699) @@ -328,11 +328,38 @@ class RepositoryTests: XCTestCase { XCTAssertEqual(subject.fullName, "mietzmithut/Test") XCTAssertEqual(subject.isPrivate, false) XCTAssertEqual(subject.repositoryDescription, "") - XCTAssertEqual(subject.isFork, false) + XCTAssertFalse(subject.isFork) XCTAssertEqual(subject.gitURL, "git://github.com/mietzmithut/Test.git") XCTAssertEqual(subject.sshURL, "git@github.com:mietzmithut/Test.git") XCTAssertEqual(subject.cloneURL, "https://github.com/mietzmithut/Test.git") XCTAssertEqual(subject.size, 132) + XCTAssertTrue(try XCTUnwrap(subject.hasWiki)) + XCTAssertEqual(subject.language, "Ruby") + + let org = try XCTUnwrap(subject.organization) + XCTAssertEqual(org.login, "github") + XCTAssertEqual(org.id, 1) + XCTAssertEqual(org.url, "https://api.github.com/orgs/github") + XCTAssertEqual(org.type, "Organization") + } + + func testUserParsingForkedRepository() { + let subject = Helper.codableFromFile("forked_repo", type: Repository.self) + XCTAssertEqual(subject.owner.login, "mietzmithut") + XCTAssertEqual(subject.owner.id, 4_672_699) + + XCTAssertEqual(subject.id, 10_824_974) + XCTAssertEqual(subject.name, "TestFork") + XCTAssertEqual(subject.fullName, "mietzmithut/TestFork") + XCTAssertEqual(subject.isPrivate, false) + XCTAssertEqual(subject.repositoryDescription, "") + XCTAssertTrue(subject.isFork) + XCTAssertEqual(subject.gitURL, "git://github.com/mietzmithut/TestFork.git") + XCTAssertEqual(subject.sshURL, "git@github.com:mietzmithut/TestFork.git") + XCTAssertEqual(subject.cloneURL, "https://github.com/mietzmithut/TestFork.git") + XCTAssertEqual(subject.size, 132) + XCTAssertFalse(try XCTUnwrap(subject.hasWiki)) + XCTAssertEqual(subject.language, "Ruby") } func testContentFileParsing() {