@@ -2,9 +2,14 @@ import ArgumentParser
22import APIBuilder
33import Foundation
44
5- struct PullRequest : Codable {
5+ struct PullRequestEvent : Codable {
66 let additions : Int
77 let deletions : Int
8+ let number : Int
9+ }
10+
11+ struct LabelsChangeRequest : Codable {
12+ let labels : [ String ]
813}
914
1015struct GithubConfiguration : APIConfiguration {
@@ -24,9 +29,12 @@ struct GithubConfiguration: APIConfiguration {
2429 }
2530}
2631
27- extension APIEndpoint where T == PullRequest {
28- static func getPullRequest( repo: String , pullRequestID: String ) -> Self {
29- APIEndpoint { " /repos/ \( repo) /pulls/ \( pullRequestID) " }
32+ extension APIEndpoint {
33+ static func setLabels( repo: String , pullRequestID: Int ) -> Self {
34+ APIEndpoint {
35+ " /repos/ \( repo) /issues/ \( pullRequestID) "
36+ HTTPMethod . put
37+ }
3038 }
3139}
3240
@@ -44,13 +52,16 @@ struct PRSizeLabeler: AsyncParsableCommand {
4452 throw StringError ( " could not load event data at \( eventPath) " )
4553 }
4654
47- print ( String ( data: eventData, encoding: . utf8) !)
55+ let pullRequestEvent = try JSONDecoder ( ) . decode ( PullRequestEvent . self, from: eventData)
56+
57+ print ( " The pull has \( pullRequestEvent. additions + pullRequestEvent. deletions) changed lines " )
4858
4959 let provider = APIProvider ( configuration: GithubConfiguration ( token: githubToken) )
50- let response = try await provider. request (
51- . getPullRequest( repo: repo, pullRequestID: " 1550 " )
60+ let body = LabelsChangeRequest ( labels: [ " XS " ] )
61+ try await provider. request (
62+ . setLabels( repo: repo, pullRequestID: pullRequestEvent. number) ,
63+ body: body
5264 )
53- print ( " The pull has \( response. additions + response. deletions) changed lines " )
5465 }
5566
5667 private func getEnv( key: String ) throws -> String {
0 commit comments