Skip to content

Commit 6315988

Browse files
committed
Added UI test for GitLab. Fixed some issues that this brought up.
1 parent 04d93ec commit 6315988

File tree

9 files changed

+528
-4
lines changed

9 files changed

+528
-4
lines changed

CCMenu.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
03412AE12B5DCD5100EFDFCB /* CCTrayAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03412AE02B5DCD5100EFDFCB /* CCTrayAPI.swift */; };
3939
03412AE32B5DCF4200EFDFCB /* CCTraySheetModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03412AE22B5DCF4200EFDFCB /* CCTraySheetModel.swift */; };
4040
034ED9C32F2A595100C7793E /* GitLabAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034ED9C22F2A595100C7793E /* GitLabAPITests.swift */; };
41+
034ED9C52F2A601C00C7793E /* GitLabTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034ED9C42F2A601C00C7793E /* GitLabTests.swift */; };
42+
034ED9C72F2A602D00C7793E /* GitLabPipelineLocalhost.json in Resources */ = {isa = PBXBuildFile; fileRef = 034ED9C62F2A602D00C7793E /* GitLabPipelineLocalhost.json */; };
43+
034ED9C92F2A604600C7793E /* GitLabPipelineRunsResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = 034ED9C82F2A604600C7793E /* GitLabPipelineRunsResponse.json */; };
44+
034ED9CF2F2A646100C7793E /* GitLabPipelineDetailsResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = 034ED9CE2F2A646100C7793E /* GitLabPipelineDetailsResponse.json */; };
4145
035F86FE2BB37A6600AD1D68 /* CCTrayAuthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035F86FD2BB37A6600AD1D68 /* CCTrayAuthView.swift */; };
4246
035F87022BB3829300AD1D68 /* PipelineListMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035F87012BB3829300AD1D68 /* PipelineListMenu.swift */; };
4347
035F87062BB4D53600AD1D68 /* SignInAtGitHubSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035F87052BB4D53600AD1D68 /* SignInAtGitHubSheet.swift */; };
@@ -174,6 +178,10 @@
174178
03412AE02B5DCD5100EFDFCB /* CCTrayAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCTrayAPI.swift; sourceTree = "<group>"; };
175179
03412AE22B5DCF4200EFDFCB /* CCTraySheetModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCTraySheetModel.swift; sourceTree = "<group>"; };
176180
034ED9C22F2A595100C7793E /* GitLabAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitLabAPITests.swift; sourceTree = "<group>"; };
181+
034ED9C42F2A601C00C7793E /* GitLabTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitLabTests.swift; sourceTree = "<group>"; };
182+
034ED9C62F2A602D00C7793E /* GitLabPipelineLocalhost.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = GitLabPipelineLocalhost.json; sourceTree = "<group>"; };
183+
034ED9C82F2A604600C7793E /* GitLabPipelineRunsResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = GitLabPipelineRunsResponse.json; sourceTree = "<group>"; };
184+
034ED9CE2F2A646100C7793E /* GitLabPipelineDetailsResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = GitLabPipelineDetailsResponse.json; sourceTree = "<group>"; };
177185
035F86FD2BB37A6600AD1D68 /* CCTrayAuthView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCTrayAuthView.swift; sourceTree = "<group>"; };
178186
035F87012BB3829300AD1D68 /* PipelineListMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PipelineListMenu.swift; sourceTree = "<group>"; };
179187
035F87052BB4D53600AD1D68 /* SignInAtGitHubSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInAtGitHubSheet.swift; sourceTree = "<group>"; };
@@ -312,6 +320,7 @@
312320
032205262B91C18600205DC6 /* CCTrayPipeline.json */,
313321
032205312B9BDDC300205DC6 /* ThreePipelines.json */,
314322
0322052A2B96708200205DC6 /* GitHubPipelineLocalhost.json */,
323+
034ED9C62F2A602D00C7793E /* GitLabPipelineLocalhost.json */,
315324
0322051C2B8FF20300205DC6 /* EmptyPipelines.json */,
316325
);
317326
path = Pipelines;
@@ -329,6 +338,8 @@
329338
032205282B96677200205DC6 /* GitHubUserReposResponse.json */,
330339
032205202B913C4E00205DC6 /* GitHubWorkflowsResponse.json */,
331340
038FF7132BB6212D0017CD4C /* GitHubBranchesResponse.json */,
341+
034ED9C82F2A604600C7793E /* GitLabPipelineRunsResponse.json */,
342+
034ED9CE2F2A646100C7793E /* GitLabPipelineDetailsResponse.json */,
332343
);
333344
path = Responses;
334345
sourceTree = "<group>";
@@ -441,6 +452,7 @@
441452
0322053E2B9E601D00205DC6 /* PipelineWindowTests.swift */,
442453
032205402B9E606600205DC6 /* CCTrayTests.swift */,
443454
032205422B9E615800205DC6 /* GitHubTests.swift */,
455+
034ED9C42F2A601C00C7793E /* GitLabTests.swift */,
444456
0322053A2B9E5DBB00205DC6 /* TestHelper.swift */,
445457
0322051E2B9139A700205DC6 /* Pipelines */,
446458
0322051F2B913BC900205DC6 /* Responses */,
@@ -762,12 +774,15 @@
762774
03A3EF942D3459D400407A6F /* GitHubUserOrgResponse.json in Resources */,
763775
03A3EF982D34650300407A6F /* GitHubReposByOrgResponse.json in Resources */,
764776
032205252B913D4000205DC6 /* GitHubReposByUserResponse.json in Resources */,
777+
034ED9C92F2A604600C7793E /* GitLabPipelineRunsResponse.json in Resources */,
765778
038FF7162BB62E6D0017CD4C /* GitHubReposByUserCCM2OnlyResponse.json in Resources */,
766779
03825EA5259FFD1500DEB003 /* DefaultPipelines.json in Resources */,
767780
038FF7142BB6212D0017CD4C /* GitHubBranchesResponse.json in Resources */,
768781
032205322B9BDDC300205DC6 /* ThreePipelines.json in Resources */,
769782
032205232B913CC000205DC6 /* GitHubWorkflowRunsResponse.json in Resources */,
783+
034ED9CF2F2A646100C7793E /* GitLabPipelineDetailsResponse.json in Resources */,
770784
0322051D2B8FF20300205DC6 /* EmptyPipelines.json in Resources */,
785+
034ED9C72F2A602D00C7793E /* GitLabPipelineLocalhost.json in Resources */,
771786
032205272B91C18600205DC6 /* CCTrayPipeline.json in Resources */,
772787
);
773788
runOnlyForDeploymentPostprocessing = 0;
@@ -908,6 +923,7 @@
908923
032205412B9E606600205DC6 /* CCTrayTests.swift in Sources */,
909924
0322053F2B9E601D00205DC6 /* PipelineWindowTests.swift in Sources */,
910925
0322053D2B9E5F9A00205DC6 /* MenuTests.swift in Sources */,
926+
034ED9C52F2A601C00C7793E /* GitLabTests.swift in Sources */,
911927
0322053B2B9E5DBB00205DC6 /* TestHelper.swift in Sources */,
912928
);
913929
runOnlyForDeploymentPostprocessing = 0;

CCMenu/Source/Miscellaneous/Keychain.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class Keychain {
8585
if service == "GitHub", let token = UserDefaults.active.string(forKey: "GitHubToken") {
8686
return token.isEmpty ? nil : token
8787
}
88+
if service == "GitLab", let token = UserDefaults.active.string(forKey: "GitLabToken") {
89+
return token.isEmpty ? nil : token
90+
}
91+
8892
if let token = cache[service] {
8993
return token
9094
}

CCMenu/Source/Server Monitor/GitLabFeedReader.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum GitLabFeedReaderError: LocalizedError {
1111
case httpError(Int)
1212
case rateLimitError(Int)
1313
case noStatusError
14+
case noDetailsError
1415

1516
var errorDescription: String? {
1617
switch self {
@@ -23,6 +24,8 @@ enum GitLabFeedReaderError: LocalizedError {
2324
return String(format: NSLocalizedString("Rate limit exceeded, next update at %@.", comment: ""), date)
2425
case .noStatusError:
2526
return "No status available for this pipeline."
27+
case .noDetailsError:
28+
return "No details available for a run of this pipeline."
2629
}
2730
}
2831
}
@@ -113,7 +116,7 @@ class GitLabFeedReader {
113116
throw GitLabFeedReaderError.invalidURLError
114117
}
115118
guard let lastBuild = try await fetchBuild(request: request) else {
116-
throw GitLabFeedReaderError.noStatusError
119+
throw GitLabFeedReaderError.noDetailsError
117120
}
118121
pipeline.status.lastBuild = lastBuild
119122
}

CCMenu/Source/Server Monitor/GitLabResponseParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class GitLabResponseParser {
6464
let prettified = source.replacingOccurrences(of: "_", with: " ").capitalized
6565
messageParts.append(prettified)
6666
}
67-
if let sha = pipeline["sha"] as? String, sha.count >= 7 {
68-
let shortSha = String(sha.prefix(7))
67+
if let sha = pipeline["sha"] as? String, sha.count >= 8 {
68+
let shortSha = String(sha.prefix(8))
6969
messageParts.append("Commit \(shortSha)")
7070
}
7171
if messageParts.count > 0 {

0 commit comments

Comments
 (0)