-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ad52ee
commit dca1c36
Showing
6 changed files
with
143 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import APIBuilder | ||
import Foundation | ||
|
||
struct GithubConfiguration: APIConfiguration { | ||
let host = URL(string: "https://api.github.com")! | ||
|
||
var requestHeaders: [String : String] { | ||
[ | ||
"Content-Type": "application/vnd.github.v3+json", | ||
"Authorization": "Bearer \(token)", | ||
] | ||
} | ||
|
||
let token: String | ||
|
||
init(token: String) { | ||
self.token = token | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import APIBuilder | ||
import ArgumentParser | ||
import Foundation | ||
|
||
// MARK: - API Types | ||
|
||
fileprivate struct PullRequestEvent: Codable { | ||
fileprivate struct PullRequest: Codable { | ||
fileprivate struct Head: Codable { | ||
let ref: String | ||
} | ||
let body: String | ||
let title: String | ||
let head: Head | ||
} | ||
let pull_request: PullRequest | ||
} | ||
|
||
struct IssueChecker: AsyncParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
commandName: "issue-checker" | ||
) | ||
|
||
func run() async throws { | ||
let eventPath = try getEnv("GITHUB_EVENT_PATH") | ||
|
||
guard let eventData = try String(contentsOfFile: eventPath).data(using: .utf8) else { | ||
throw StringError("could not load event data at \(eventPath)") | ||
} | ||
|
||
let pullRequestEvent = try JSONDecoder().decode(PullRequestEvent.self, from: eventData) | ||
|
||
print(pullRequestEvent.pull_request.body) | ||
print(pullRequestEvent.pull_request.title) | ||
print(pullRequestEvent.pull_request.head.ref) | ||
|
||
let issuePrefix = try getInputEnv("ISSUE_CHECKER_PREFIX") as String | ||
|
||
let inputsToCheck = [ | ||
pullRequestEvent.pull_request.body, | ||
pullRequestEvent.pull_request.title, | ||
pullRequestEvent.pull_request.head.ref, | ||
] | ||
|
||
for input in inputsToCheck { | ||
let range = input | ||
.lowercased() | ||
.range( | ||
of: "\(issuePrefix.lowercased())\\d{1,}", | ||
options: .regularExpression | ||
) | ||
|
||
if let range = range { | ||
print("Found \(input[range])") | ||
return | ||
} | ||
} | ||
|
||
throw StringError("Could not find issue in the PR") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
name: Copilot Swift PR Actions | ||
description: Collection of PR Actions geared mostly towards iOS projects | ||
|
||
inputs: | ||
action_name: | ||
description: 'Which action should be invoked' | ||
required: true | ||
runs: | ||
using: docker | ||
image: Dockerfile | ||
args: | ||
- ${{ inputs.action_name }} | ||
|