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
85 changes: 85 additions & 0 deletions .surface

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .surface-breaking
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,4 @@ FLAG basecamp chat messages --campfire type=string
FLAG basecamp chat post --campfire type=string
FLAG basecamp chat show --campfire type=string
FLAG basecamp chat upload --campfire type=string

12 changes: 9 additions & 3 deletions internal/commands/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ You can pass either a card ID or a Basecamp URL:
}

dlDir := addDownloadAttachmentsFlag(cmd)
cf := addCommentFlags(cmd, false)

cmd.RunE = func(cmd *cobra.Command, args []string) error {
app := appctx.FromContext(cmd.Context())
Expand All @@ -288,6 +289,8 @@ You can pass either a card ID or a Basecamp URL:
return convertSDKError(err)
}

enrichment := fetchCommentsForRecording(cmd.Context(), app, cardIDStr, cf)

opts := []output.ResponseOption{
output.WithSummary(fmt.Sprintf("Card #%s: %s", cardIDStr, card.Title)),
output.WithBreadcrumbs(
Expand All @@ -300,6 +303,7 @@ You can pass either a card ID or a Basecamp URL:
}

data := any(card)
attachmentNotice := ""
contentAtts := downloadableAttachments(richtext.ParseAttachments(card.Content))
descAtts := downloadableAttachments(richtext.ParseAttachments(card.Description))
total := len(contentAtts) + len(descAtts)
Expand All @@ -317,17 +321,19 @@ You can pass either a card ID or a Basecamp URL:
if len(descAtts) > 0 {
data = withAttachmentMeta(data, "description", descAtts, descDL)
}
notice := fmt.Sprintf("%d attachment(s) — download: basecamp attachments download %s",
attachmentNotice = fmt.Sprintf("%d attachment(s) — download: basecamp attachments download %s",
total, cardIDStr)
if dl != nil && dl.Notice != "" {
notice += "; " + dl.Notice
attachmentNotice += "; " + dl.Notice
}
opts = append(opts,
output.WithNotice(notice),
output.WithBreadcrumbs(attachmentBreadcrumb(cardIDStr, total)),
)
}

data, extraOpts := enrichment.apply(data, attachmentNotice)
opts = append(opts, extraOpts...)

return app.OK(data, opts...)
}

Expand Down
14 changes: 13 additions & 1 deletion internal/commands/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ func runChatUpload(cmd *cobra.Command, app *appctx.App, chatID, project, filePat
}

func newChatLineShowCmd(project, chatID *string) *cobra.Command {
var cf *commentFlags

cmd := &cobra.Command{
Use: "line <id|url>",
Aliases: []string{"show"},
Expand Down Expand Up @@ -697,9 +699,13 @@ You can pass either a line ID or a Basecamp line URL:
if line.Creator != nil {
creatorName = line.Creator.Name
}

enrichment := fetchCommentsForRecording(cmd.Context(), app, lineID, cf)
data, commentOpts := enrichment.apply(line, "")
summary := fmt.Sprintf("Line #%s by %s", lineID, creatorName)

return app.OK(line,
opts := make([]output.ResponseOption, 0, 4+len(commentOpts))
opts = append(opts,
output.WithSummary(summary),
output.WithEntity("chat_line"),
output.WithDisplayData(chatLineDisplayData(line)),
Expand All @@ -716,8 +722,14 @@ You can pass either a line ID or a Basecamp line URL:
},
),
)
opts = append(opts, commentOpts...)

return app.OK(data, opts...)
},
}

cf = addCommentFlags(cmd, false)

return cmd
}

Expand Down
81 changes: 55 additions & 26 deletions internal/commands/checkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ func newCheckinsQuestionCmd(project *string) *cobra.Command {
Use: "question <id|url>",
Short: "Show or manage a question",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Show help when invoked with no arguments
if len(args) == 0 {
return missingArg(cmd, "<id|url>")
}
return runCheckinsQuestionShow(cmd, *project, args[0])
},
}

cf := addCommentFlags(cmd, false)

cmd.RunE = func(cmd *cobra.Command, args []string) error {
// Show help when invoked with no arguments
if len(args) == 0 {
return missingArg(cmd, "<id|url>")
}
return runCheckinsQuestionShow(cmd, *project, args[0], cf)
}

cmd.AddCommand(
Expand All @@ -172,7 +175,7 @@ func newCheckinsQuestionCmd(project *string) *cobra.Command {
}

func newCheckinsQuestionShowCmd(project *string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "show <id|url>",
Short: "Show question details",
Long: `Display details of a check-in question.
Expand All @@ -181,13 +184,18 @@ You can pass either a question ID or a Basecamp URL:
basecamp checkins question show 789 --in my-project
basecamp checkins question show https://3.basecamp.com/123/buckets/456/questionnaires/questions/789`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runCheckinsQuestionShow(cmd, *project, args[0])
},
}

cf := addCommentFlags(cmd, false)

cmd.RunE = func(cmd *cobra.Command, args []string) error {
return runCheckinsQuestionShow(cmd, *project, args[0], cf)
}

return cmd
}

func runCheckinsQuestionShow(cmd *cobra.Command, project, questionIDStr string) error {
func runCheckinsQuestionShow(cmd *cobra.Command, project, questionIDStr string, cf *commentFlags) error {
app := appctx.FromContext(cmd.Context())

if err := ensureAccount(cmd, app); err != nil {
Expand Down Expand Up @@ -230,9 +238,12 @@ func runCheckinsQuestionShow(cmd *cobra.Command, project, questionIDStr string)
return convertSDKError(err)
}

enrichment := fetchCommentsForRecording(cmd.Context(), app, questionIDStr, cf)
data, commentOpts := enrichment.apply(question, "")
summary := fmt.Sprintf("%s (%d answers)", question.Title, question.AnswersCount)

return app.OK(question,
opts := make([]output.ResponseOption, 0, 2+len(commentOpts))
opts = append(opts,
output.WithSummary(summary),
output.WithBreadcrumbs(
output.Breadcrumb{
Expand All @@ -247,6 +258,9 @@ func runCheckinsQuestionShow(cmd *cobra.Command, project, questionIDStr string)
},
),
)
opts = append(opts, commentOpts...)

return app.OK(data, opts...)
}

func newCheckinsQuestionCreateCmd(project *string) *cobra.Command {
Expand Down Expand Up @@ -620,13 +634,16 @@ func newCheckinsAnswerCmd(project *string) *cobra.Command {
Use: "answer <id|url>",
Short: "Show or manage an answer",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Show help when invoked with no arguments
if len(args) == 0 {
return missingArg(cmd, "<id|url>")
}
return runCheckinsAnswerShow(cmd, *project, args[0])
},
}

cf := addCommentFlags(cmd, false)

cmd.RunE = func(cmd *cobra.Command, args []string) error {
// Show help when invoked with no arguments
if len(args) == 0 {
return missingArg(cmd, "<id|url>")
}
return runCheckinsAnswerShow(cmd, *project, args[0], cf)
}

cmd.AddCommand(
Expand All @@ -639,7 +656,7 @@ func newCheckinsAnswerCmd(project *string) *cobra.Command {
}

func newCheckinsAnswerShowCmd(project *string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "show <id|url>",
Short: "Show answer details",
Long: `Display details of a check-in answer.
Expand All @@ -648,13 +665,18 @@ You can pass either an answer ID or a Basecamp URL:
basecamp checkins answer show 789 --in my-project
basecamp checkins answer show https://3.basecamp.com/123/buckets/456/question_answers/789`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runCheckinsAnswerShow(cmd, *project, args[0])
},
}

cf := addCommentFlags(cmd, false)

cmd.RunE = func(cmd *cobra.Command, args []string) error {
return runCheckinsAnswerShow(cmd, *project, args[0], cf)
}

return cmd
}

func runCheckinsAnswerShow(cmd *cobra.Command, project, answerIDStr string) error {
func runCheckinsAnswerShow(cmd *cobra.Command, project, answerIDStr string, cf *commentFlags) error {
app := appctx.FromContext(cmd.Context())

if err := ensureAccount(cmd, app); err != nil {
Expand Down Expand Up @@ -705,14 +727,18 @@ func runCheckinsAnswerShow(cmd *cobra.Command, project, answerIDStr string) erro
if len(date) > 10 {
date = date[:10]
}

enrichment := fetchCommentsForRecording(cmd.Context(), app, answerIDStr, cf)
data, commentOpts := enrichment.apply(answer, "")
summary := fmt.Sprintf("Answer by %s on %s", author, date)

questionID := ""
if answer.Parent != nil {
questionID = strconv.FormatInt(answer.Parent.ID, 10)
}

return app.OK(answer,
opts := make([]output.ResponseOption, 0, 2+len(commentOpts))
opts = append(opts,
output.WithSummary(summary),
output.WithBreadcrumbs(
output.Breadcrumb{
Expand All @@ -727,6 +753,9 @@ func runCheckinsAnswerShow(cmd *cobra.Command, project, answerIDStr string) erro
},
),
)
opts = append(opts, commentOpts...)

return app.OK(data, opts...)
}

func newCheckinsAnswerCreateCmd(project *string) *cobra.Command {
Expand Down
Loading
Loading