Skip to content

Commit 4549a10

Browse files
committed
add label to pr
1 parent 9713544 commit 4549a10

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

Package.resolved

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/copilot-action/PRSizeLabeler.swift

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import ArgumentParser
22
import APIBuilder
33
import 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

1015
struct 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

Comments
 (0)