Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Sources/Services/RunnerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,27 @@ class RunnerManager: ObservableObject {
}
}

func currentWorkflowJob(for runnerID: UUID) -> WorkflowJobSummary? {
activeWorkflowJobs[runnerID]
}

func openCurrentWorkflowRun(for runnerID: UUID) {
guard let runURL = Self.currentWorkflowRunURL(from: activeWorkflowJobs[runnerID]) else {
return
}

NSWorkspace.shared.open(runURL)
}

nonisolated static func currentWorkflowRunURL(from job: WorkflowJobSummary?) -> URL? {
job?.run.htmlURL
}

nonisolated static func currentWorkflowDisplayName(from job: WorkflowJobSummary?) -> String? {
guard let job else { return nil }
return job.run.name.isEmpty ? job.name : job.run.name
}

private func refreshUpdateStatusMessage() {
if let availableUpdate {
updateStatusMessage = "Version \(availableUpdate.latestVersion) is available."
Expand Down
24 changes: 24 additions & 0 deletions Sources/Views/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,25 @@ struct RunnerRow: View {
.font(.caption)
.foregroundColor(.secondary)

if runner.status == .running,
runner.busy,
let currentJob = runnerManager.currentWorkflowJob(for: runner.id),
let workflowName = RunnerManager.currentWorkflowDisplayName(from: currentJob) {
Button(action: {
runnerManager.openCurrentWorkflowRun(for: runner.id)
}) {
HStack(spacing: 4) {
Image(systemName: "link")
Text("View \(workflowName)")
.lineLimit(1)
}
.font(.caption2)
.foregroundColor(.accentColor)
}
.buttonStyle(.plain)
.help("Open current GitHub Actions run")
}

HStack(spacing: 4) {
// Isolation mode indicator
if let mode = runner.isolationMode {
Expand Down Expand Up @@ -348,6 +367,11 @@ struct RunnerRow: View {
Button("Stop") {
Task { try? await runnerManager.stopRunner(runner.id) }
}
if runner.busy, runnerManager.currentWorkflowJob(for: runner.id) != nil {
Button("Open Current Job") {
runnerManager.openCurrentWorkflowRun(for: runner.id)
}
}
} else {
Button("Start") {
Task { try? await runnerManager.startRunner(runner.id) }
Expand Down
32 changes: 32 additions & 0 deletions Tests/MacRunnerTests/MacRunnerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,36 @@ final class MacRunnerTests: XCTestCase {
XCTAssertEqual(payload.body, "omniaura/mac-runner - Nightly (failure)")
XCTAssertEqual(payload.runURL, run.htmlURL)
}

func testRunnerManagerCurrentWorkflowHelpersPreferRunNameAndURL() {
let runURL = URL(string: "https://github.com/omniaura/mac-runner/actions/runs/42")!
let job = WorkflowJobSummary(
id: 8,
name: "test",
status: "in_progress",
conclusion: nil,
runnerName: "runner-1",
run: WorkflowRunSummary(id: 42, name: "Nightly", htmlURL: runURL)
)

XCTAssertEqual(RunnerManager.currentWorkflowDisplayName(from: job), "Nightly")
XCTAssertEqual(RunnerManager.currentWorkflowRunURL(from: job), runURL)
}

func testRunnerManagerCurrentWorkflowHelpersFallBackToJobName() {
let job = WorkflowJobSummary(
id: 9,
name: "integration",
status: "in_progress",
conclusion: nil,
runnerName: "runner-1",
run: WorkflowRunSummary(
id: 43,
name: "",
htmlURL: URL(string: "https://github.com/omniaura/mac-runner/actions/runs/43")!
)
)

XCTAssertEqual(RunnerManager.currentWorkflowDisplayName(from: job), "integration")
}
}
Loading