-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(swift-ios): embed an exact build changelog with links #5969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
saphid
wants to merge
7
commits into
pingdotgg:t3code/rebuild-mobile-app-swift
Choose a base branch
from
saphid:saphid/swiftui-changelog-v2
base: t3code/rebuild-mobile-app-swift
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
84a4d8f
feat(swift-ios): show exact build changelog in app
saphid 64a8033
feat(swift-ios): link changelog commits and pull requests
saphid 68fc1a3
fix(swift-ios): keep changelog independent of version settings
saphid 3a8fcf2
fix(swift-ios): make embedded changelog upstream-safe
saphid 51fa7e9
fix(swift-ios): bound portable changelog generation
saphid cb69786
fix(swift-ios): tolerate unavailable git metadata
saphid 1e1f4a9
fix(swift-ios): clarify embedded changelog entries
saphid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,204 @@ | ||
| import Foundation | ||
| import SwiftUI | ||
|
|
||
| struct BuildChangelog: Codable, Equatable, Sendable { | ||
| struct Entry: Codable, Equatable, Identifiable, Sendable { | ||
| let commit: String | ||
| let title: String | ||
| let summary: String | ||
| let pullRequest: Int? | ||
| let pullRequestURL: URL? | ||
| let committedAt: Date? | ||
|
|
||
| var id: String { commit } | ||
| var shortCommit: String { String(commit.prefix(7)) } | ||
| var displaySummary: String? { | ||
| let value = summary.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard !value.isEmpty, | ||
| value.localizedCaseInsensitiveCompare( | ||
| title.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| ) != .orderedSame else { | ||
| return nil | ||
| } | ||
| return value | ||
| } | ||
| } | ||
|
|
||
| let revision: String | ||
| let baseRevision: String? | ||
| let repositoryURL: URL? | ||
| let generatedBy: String | ||
| let entries: [Entry] | ||
|
|
||
| static let embedded = load(info: Bundle.main.infoDictionary) | ||
|
|
||
| static func load(info: [String: Any]?) -> BuildChangelog? { | ||
| guard let encoded = info?["T3BuildChangelog"] as? String, | ||
| !encoded.isEmpty, | ||
| !encoded.hasPrefix("$("), | ||
| let data = Data(base64Encoded: encoded) | ||
| else { return nil } | ||
|
|
||
| let decoder = JSONDecoder() | ||
| decoder.dateDecodingStrategy = .iso8601 | ||
| return try? decoder.decode(BuildChangelog.self, from: data) | ||
| } | ||
| } | ||
|
|
||
| struct BuildChangelogView: View { | ||
| let changelog: BuildChangelog? | ||
| let versionLabel: String | ||
|
|
||
| var body: some View { | ||
| ScrollView { | ||
| LazyVStack(alignment: .leading, spacing: 0) { | ||
| header.padding(.bottom, 24) | ||
|
|
||
| if let changelog, !changelog.entries.isEmpty { | ||
| if let latest = changelog.entries.last { | ||
| latestChange(latest, repositoryURL: changelog.repositoryURL) | ||
| .padding(.bottom, 28) | ||
| } | ||
|
|
||
| let earlierEntries = Array(changelog.entries.dropLast().reversed()) | ||
| if !earlierEntries.isEmpty { | ||
| Text("Earlier in this build") | ||
| .font(T3Typography.homeTitle) | ||
| .foregroundStyle(T3Colors.textPrimary) | ||
| .padding(.bottom, 16) | ||
| } | ||
| ForEach(Array(earlierEntries.enumerated()), id: \.element.id) { index, entry in | ||
| milestone( | ||
| entry, | ||
| repositoryURL: changelog.repositoryURL, | ||
| isLast: index == earlierEntries.count - 1 | ||
| ) | ||
| } | ||
| } else if changelog == nil { | ||
| ContentUnavailableView( | ||
| "No build changelog", | ||
| systemImage: "list.bullet.rectangle", | ||
| description: Text("This build did not include an embedded changelog.") | ||
| ) | ||
| .frame(maxWidth: .infinity) | ||
| .padding(.top, 48) | ||
| } else { | ||
| ContentUnavailableView( | ||
| "No changes in this build", | ||
| systemImage: "checkmark.circle", | ||
| description: Text( | ||
| changelog?.baseRevision == nil | ||
| ? "This build did not configure a base revision for comparison." | ||
| : "No commits were found between this build and its configured base revision." | ||
| ) | ||
| ) | ||
| .frame(maxWidth: .infinity) | ||
| .padding(.top, 48) | ||
| } | ||
| } | ||
| .padding(20) | ||
| } | ||
| .background(T3Colors.background) | ||
| .navigationTitle("What’s in this build") | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| } | ||
|
|
||
| private var header: some View { | ||
| VStack(alignment: .leading, spacing: 6) { | ||
| Text("Version \(versionLabel)") | ||
| .font(T3Typography.homeTitle) | ||
| .foregroundStyle(T3Colors.textPrimary) | ||
| if let changelog { | ||
| Text("Revision \(String(changelog.revision.prefix(7))) · Summaries by \(changelog.generatedBy)") | ||
| .font(T3Typography.supporting) | ||
| .foregroundStyle(T3Colors.textSecondary) | ||
| } | ||
| } | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| } | ||
|
|
||
| private func latestChange(_ entry: BuildChangelog.Entry, repositoryURL: URL?) -> some View { | ||
| VStack(alignment: .leading, spacing: 10) { | ||
| Label("New in this version", systemImage: "sparkles") | ||
| .font(T3Typography.homeTitle) | ||
| .foregroundStyle(T3Colors.accent) | ||
| Text(entry.title) | ||
| .font(T3Typography.threadBody) | ||
| .fontWeight(.semibold) | ||
| .foregroundStyle(T3Colors.textPrimary) | ||
| if let summary = entry.displaySummary { | ||
| Text(summary) | ||
| .font(T3Typography.supporting) | ||
| .foregroundStyle(T3Colors.textSecondary) | ||
| .fixedSize(horizontal: false, vertical: true) | ||
| } | ||
| changeLinks(entry, repositoryURL: repositoryURL) | ||
| } | ||
| .padding(16) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .background(T3Colors.surface, in: RoundedRectangle(cornerRadius: 14)) | ||
| .overlay { | ||
| RoundedRectangle(cornerRadius: 14) | ||
| .stroke(T3Colors.border, lineWidth: 1) | ||
| } | ||
| } | ||
|
|
||
| private func milestone( | ||
| _ entry: BuildChangelog.Entry, | ||
| repositoryURL: URL?, | ||
| isLast: Bool | ||
| ) -> some View { | ||
| HStack(alignment: .top, spacing: 14) { | ||
| VStack(spacing: 0) { | ||
| Circle() | ||
| .fill(T3Colors.accent) | ||
| .frame(width: 10, height: 10) | ||
| .padding(.top, 5) | ||
| if !isLast { | ||
| Rectangle() | ||
| .fill(T3Colors.border) | ||
| .frame(width: 2) | ||
| .frame(minHeight: 92) | ||
| } | ||
| } | ||
|
|
||
| VStack(alignment: .leading, spacing: 6) { | ||
| Text(entry.title) | ||
| .font(T3Typography.threadBody) | ||
| .fontWeight(.semibold) | ||
| .foregroundStyle(T3Colors.textPrimary) | ||
| if let summary = entry.displaySummary { | ||
| Text(summary) | ||
| .font(T3Typography.supporting) | ||
| .foregroundStyle(T3Colors.textSecondary) | ||
| .fixedSize(horizontal: false, vertical: true) | ||
| } | ||
| changeLinks(entry, repositoryURL: repositoryURL) | ||
| } | ||
| .padding(.bottom, isLast ? 0 : 22) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| } | ||
| } | ||
|
|
||
| private func changeLinks( | ||
| _ entry: BuildChangelog.Entry, | ||
| repositoryURL: URL? | ||
| ) -> some View { | ||
| HStack(spacing: 12) { | ||
| if let repositoryURL { | ||
| Link(destination: repositoryURL.appending(path: "commit/\(entry.commit)")) { | ||
| Label(entry.shortCommit, systemImage: "point.topleft.down.to.point.bottomright.curvepath") | ||
| } | ||
| } else { | ||
| Text(entry.shortCommit) | ||
| } | ||
| if let pullRequest = entry.pullRequest, let pullRequestURL = entry.pullRequestURL { | ||
| Link(destination: pullRequestURL) { | ||
| Label("PR #\(pullRequest)", systemImage: "arrow.triangle.pull") | ||
| } | ||
| } | ||
| } | ||
| .font(.caption.monospaced()) | ||
| .foregroundStyle(T3Colors.accent) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.