nerdishbynature / octokit.swift

A Swift API Client for GitHub and GitHub Enterprise
MIT License
488 stars 126 forks source link

Issue with `patchIssue` #184

Closed gregorFeigel closed 4 months ago

gregorFeigel commented 4 months ago

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.

pietbrauer commented 4 months ago

Hey, I doubt it's your fault. For posting the issue we set the dateDecodingStrategy correctly (https://github.com/nerdishbynature/octokit.swift/blob/main/OctoKit/Issue.swift#L308C9-L308C77) but for patching (both methods) we don't.

https://github.com/nerdishbynature/octokit.swift/blob/main/OctoKit/Issue.swift#L333-L334 https://github.com/nerdishbynature/octokit.swift/blob/main/OctoKit/Issue.swift#L364-L365

PRs are highly welcome, else I try to fix it tonight.

gregorFeigel commented 4 months ago

I just opened a PR.

Another little thing I noticed: If I run close and fetch all issues with a certain label (thread), in many cases, the closedAt property of the return is not changed, although the GitHub Site shows the issue as closed. Any Idea why? Like is there an API delay?

try await thread.close(issue: n)
let thread = try await github.thread(for: node.nodeID)
func thread(for nodeID: String) async throws -> GitHubIssueThread {
     guard let github = github else { throw state }
     let issues = try await github.issues(owner: owner, repository: repo, state: .all).filter { issue in
         guard let labels = issue.labels else { return false }
         return labels.contains(where: { $0.name != nil && $0.name! == nodeID })
     }
     return .init(gitHub: self, issues: issues)
}
pietbrauer commented 4 months ago

Closed with #185