nerdishbynature / octokit.swift Goto Github PK
View Code? Open in Web Editor NEWA Swift API Client for GitHub and GitHub Enterprise
License: MIT License
A Swift API Client for GitHub and GitHub Enterprise
License: MIT License
Sample code:
import OctoKit
import Foundation
let config = TokenConfiguration("secret")
var done = false
let client = Octokit(config)
client.issues(owner: "rubiojr", repository: "test") { response in
switch response {
case .success(let issues):
print(issues[0].labelsURL!)
case .failure(let error):
print(error)
}
done = true
}
repeat {
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.1))
} while !done
The exception:
Compile Swift Module 'OctoKit' (14 sources)
Compile Swift Module 'labbelier' (1 sources)
Linking ./.build/x86_64-apple-macosx10.10/debug/labbelier
dataCorrupted(Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "labels_url", intValue: nil)], debugDescription: "Invalid URL string.", underlyingError: nil))
I believe this happens because it may return something like https://api.github.com/repos/rubiojr/test/issues/3/labels{/name}
as the value of labels_url
(see https://developer.github.com/v3/issues/#list-issues-for-a-repository) and URL
doesn't like that? Something like:
import Foundation
struct Example: Decodable {
let url: URL?
}
let foo = try JSONDecoder().decode(Example.self, from: """
{ "url": "https://api.github.com/repos/rubiojr/test/issues/3/labels{/name}" }
""".data(using: .utf8)!)
Causes:
Fatal error: Error raised at top level: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "url", intValue: nil)], debugDescription: "Invalid URL string.", underlyingError: nil)): file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.42/src/swift/stdlib/public/core/ErrorType.swift, line 191
As a workaround, I'm using a local copy of the lib changing
octokit.swift/OctoKit/Issue.swift
Line 16 in a3b0ead
String?
instead, which seems to be working as expected but, is there a better way?
swift --version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0
The url for org repos is:
/org/\(name)/repos
But the code only uses:
/user/\(name)/repos
Which lists public repos, but not private ones.
I'm using Octokit(config).pullRequests(owner: , repository: )
but if I make a change in my Github PR it doesn't fetch the new data when called.
Looks like it is caching the response for a while.
Is there any way to disable this, and always fetch from a fresh api call?
Hey, I just came across the following problem (hope this is not an application fault).
I want to close an issue using the async throws
patchIssue
function as shown in the README. However I keep on getting the following error:
typeMismatch(Swift.Double, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "closed_at", intValue: nil)], debugDescription: "Expected to decode Double but found a string instead.", underlyingError: nil))
My code snippet:
func close(issue: Issue) async throws {
guard let github = github else { throw state }
// no idea if this is necessary at all - won't work with and without
issue.closedAt = Date()
issue.closedBy = try await github.me()
_ = try await github.patchIssue(owner: owner, repository: repo, number: issue.number, state: .closed)
}
Any help appreciated, thanks.
Hi,
Big fan of this project. One problem though, I have tried the OAuth config settings and gotten the code
attribute. I followed the code example you provided in the README.md
but printing out user.login
does not work. Mind helping me out here?
Hi,
I have cloned this repo and I have tried running it in Xcode but the included Unit Tests does not pass due to multiple missing JSON
files. For example test FollowTests.testGetMyFollowers()
fails due to:
Fatal error: Unexpectedly found nil while unwrapping an Optional value
2019-05-09 14:25:44.158687+0200 xctest[47127:288344] Fatal error: Unexpectedly found nil while unwrapping an Optional value
the unit test is looking for a JSON
file named users
but this file is not included in the repo (I am using master
branch).
I am running octokit.swift
library on macOS Mojave 10.14.4 (18E227)
Hi ๐ ,
I want to get the raw contents of a file. I looked at the available API calls but this was not found.
So I was thinking of me opening a PR about it.
What do you think?
Do you have any plans to support Pull Requests and Issues? In particular, the topics that are related to a specific user, so f.e. all Pull Request of User XY.
Posting an issue with assignee and labels parameter does not work currently. It looks like the function supports it, but the call is not actually being made.
Error message:
'OctoKit' ***/.build/checkouts/octokit.swift: error: target at '/ ***/.build/checkouts/octokit.swift' contains mixed language source files; feature not supported
Blocking danger/swift#327
Is there a way to fetch a repository tags? I'm not finding anything about tags other than the Releases tagName
hi ,sorry bro but your app dont run :\
Great project ... is there anything on the horizon to add downloading a repo - getting list of contents (like a zip archive) and optionally d/l the repo to a given folder location ?
Will this great project support for OSX development via Cocoapods?
Really need it:)
Hi,
I can't seem to get the PRs in private repos and get the error:
Error Domain=com.nerdishbynature.octokit Code=404 "(null)" UserInfo={RequestKitErrorKey={ "documentation_url" = "https://docs.github.com/rest/reference/pulls#list-pull-requests"; message = "Not Found"; }}
I've given the repo
scope and feel it should be working.
Any help would be appreciated!
Usman
I'm planning to do a PR for refs and trees (then eventually files). Thought I'd share my plan and get any feedback. Here is the draft interface for trees (refs should be straightforward), the unique bit might be in how the tree structure gets returned. Composing the objects into a tree is an extra step that makes sense to me, but doesn't mirror the API response, so I'm interested to hear your thoughts.
Also, I'm wondering if truncated trees should be treated as an error response, it could certainly just be a property on the Tree
object but it feels like its an error to not more explicitly handle it, I could see using a TreeResponse
enum with the response case of Truncated
that still passes along the tree.
/**
Getting a tree
- parameter owner: The user or organization that owns the repository.
- parameter repository: The name of the repository.
- parameter sha: sha of the commit to get the tree from
- parameter recursively: If true, composes the Tree's subdirectories in the Tree's entries property
- parameter completion: Callback for the outcome of the fetch.
Completion is called with a root Tree object that has an array property entries: [Tree]?
If recursive is true, subdirectories will have further Tree objects in their entries
*/
func tree(owner: String,
repository: String,
sha: String,
recursively: Bool,
completion: (response: Response<Tree>) -> Void)
GET /issues
GET /user/issues
GET /orgs/:org/issues
GET /repos/:owner/:repo/issues
GET /repos/:owner/:repo/issues/:number
POST /repos/:owner/:repo/issues
PATCH /repos/:owner/:repo/issues/:number
PUT /repos/:owner/:repo/issues/:number/lock
DELETE /repos/:owner/:repo/issues/:number/lock
GET /repos/:owner/:repo/assignees
GET /repos/:owner/:repo/issues/:number/comments
GET /repos/:owner/:repo/issues/comments
GET /repos/:owner/:repo/issues/comments/:id
POST /repos/:owner/:repo/issues/:number/comments
PATCH /repos/:owner/:repo/issues/comments/:id
DELETE /repos/:owner/:repo/issues/comments/:id1
GET /repos/:owner/:repo/issues/:issue_number/events
GET /repos/:owner/:repo/issues/events
GET /repos/:owner/:repo/issues/events/:id
GET /repos/:owner/:repo/labels
GET /repos/:owner/:repo/labels/:name1
POST /repos/:owner/:repo/labels
PATCH /repos/:owner/:repo/labels/:name
DELETE /repos/:owner/:repo/labels/:name
GET /repos/:owner/:repo/issues/:number/labels
POST /repos/:owner/:repo/issues/:number/labels
DELETE /repos/:owner/:repo/issues/:number/labels/:name
PUT /repos/:owner/:repo/issues/:number/labels
DELETE /repos/:owner/:repo/issues/:number/labels
GET /repos/:owner/:repo/milestones/:number/labels
GET /repos/:owner/:repo/milestones
GET /repos/:owner/:repo/milestones/:number
POST /repos/:owner/:repo/milestones
PATCH /repos/:owner/:repo/milestones/:number
DELETE /repos/:owner/:repo/milestones/:number
Hi!
First off, thanks for the great tool ๐
I have successfully automated a github release, but I can't find any way how to upload an asset - is this supported?
(I am talking about this endpoint)
If not, I can give a helping hand and try to take a stab at it ๐ช
CircleCI iOS is becoming a paid feature.
Please use the Authorization HTTP header instead, as using the
access_token
query parameter is deprecated.
As mentioned by GitHub. It's no longer recommended to use this together with the GitHub API. It's recommended to change code by making use of an Authentication header instead.
For example:
let configuration = URLSessionConfiguration.default
let username = "<github_username>"
let token = "<github_access_token>"
let authorizationToken = "\(username):\(token)".data(using: .utf8)!.base64EncodedString()
configuration.httpAdditionalHeaders = ["Authorization": "Basic \(token)"]
let session = URLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
Obviously, it would be nicer to integrate this into OctoKit for implementers to easily use.
Hi there! First of all, thanks for awesome framework!
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool
This function is deprecated, what should we use?
This feature had to be disabled in #85 in order to get the builds to pass, which were previously timing out when cloning the specs repo.
let config = TokenConfiguration(GITHUB_TOKEN)
let gh = Octokit(config)
gh.repository(owner: owner, name: name) { response in
switch response {
case .success(let repository):
stars = repository.stargazersCount
if let unwrapped = stars {
print("\(name) : \(unwrapped)โญ๏ธ")
}
break
case .failure(let error):
print(error)
break
}
this code works fine without token (but with token gets error:
Error Domain=com.nerdishbynature.octokit Code=401 "(null)" UserInfo={RequestKitErrorKey={
"documentation_url" = "https://developer.github.com/v3";
message = "Bad credentials";
}}
I tried to send the same token by curl - everything works fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.