MCPcopy Index your code
hub / github.com/coder/coder / ChatDiffStatus

Function ChatDiffStatus

coderd/database/db2sdk/db2sdk.go:2016–2094  ·  view source on GitHub ↗

ChatDiffStatus converts a database.ChatDiffStatus to a codersdk.ChatDiffStatus. When status is nil an empty value containing only the chatID is returned.

(chatID uuid.UUID, status *database.ChatDiffStatus)

Source from the content-addressed store, hash-verified

2014// codersdk.ChatDiffStatus. When status is nil an empty value
2015// containing only the chatID is returned.
2016func ChatDiffStatus(chatID uuid.UUID, status *database.ChatDiffStatus) codersdk.ChatDiffStatus {
2017 result := codersdk.ChatDiffStatus{
2018 ChatID: chatID,
2019 }
2020 if status == nil {
2021 return result
2022 }
2023
2024 result.ChatID = status.ChatID
2025 if status.Url.Valid {
2026 u := strings.TrimSpace(status.Url.String)
2027 if u != "" {
2028 result.URL = &u
2029 }
2030 }
2031 if result.URL == nil {
2032 // Try to build a branch URL from the stored origin.
2033 // Since this function does not have access to the API
2034 // instance, we construct a GitHub provider directly as
2035 // a best-effort fallback.
2036 // TODO: This uses the default github.com API base URL,
2037 // so branch URLs for GitHub Enterprise instances will
2038 // be incorrect. To fix this, this function would need
2039 // access to the external auth configs.
2040 gp, _ := gitprovider.New("github", "", nil)
2041 if gp != nil {
2042 if owner, repo, _, ok := gp.ParseRepositoryOrigin(status.GitRemoteOrigin); ok {
2043 branchURL := gp.BuildBranchURL(owner, repo, status.GitBranch)
2044 if branchURL != "" {
2045 result.URL = &branchURL
2046 }
2047 }
2048 }
2049 }
2050 if status.PullRequestState.Valid {
2051 pullRequestState := strings.TrimSpace(status.PullRequestState.String)
2052 if pullRequestState != "" {
2053 result.PullRequestState = &pullRequestState
2054 }
2055 }
2056 result.PullRequestTitle = status.PullRequestTitle
2057 result.PullRequestDraft = status.PullRequestDraft
2058 result.ChangesRequested = status.ChangesRequested
2059 result.Additions = status.Additions
2060 result.Deletions = status.Deletions
2061 result.ChangedFiles = status.ChangedFiles
2062 if status.AuthorLogin.Valid {
2063 result.AuthorLogin = &status.AuthorLogin.String
2064 }
2065 if status.AuthorAvatarUrl.Valid {
2066 result.AuthorAvatarURL = &status.AuthorAvatarUrl.String
2067 }
2068 if status.BaseBranch.Valid {
2069 result.BaseBranch = &status.BaseBranch.String
2070 }
2071 if status.HeadBranch.Valid {
2072 result.HeadBranch = &status.HeadBranch.String
2073 }

Callers 5

TestWatchChatsFunction · 0.92
ChatFunction · 0.70
ChildChatRowsFunction · 0.70
ChatRowsWithChildrenFunction · 0.70

Calls 3

NewFunction · 0.92
ParseRepositoryOriginMethod · 0.65
BuildBranchURLMethod · 0.65

Tested by 1

TestWatchChatsFunction · 0.74