Skip to content
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

gh status: show status even if a comment 404s #7873

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 22 additions & 10 deletions pkg/cmd/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,23 +286,35 @@ func (s *StatusGetter) LoadNotifications() error {
if !ok {
return nil
}
if actual, err := s.ActualMention(n.Subject.LatestCommentURL); actual != "" && err == nil {
var preview string
if actual, err := s.ActualMention(n.Subject.LatestCommentURL); err == nil {
preview = actual
} else {
var httpErr api.HTTPError
if !errors.As(err, &httpErr) {
abortFetching()
return fmt.Errorf("could not fetch comment: %w", err)
}
if httpErr.StatusCode == 403 {
s.addAuthError(httpErr.Message, factory.SSOURL())
return nil
} else if httpErr.StatusCode == 404 {
preview = "(could not find comment)"
} else {
abortFetching()
return fmt.Errorf("could not fetch comment: %w", err)
}
}

if preview != "" {
rwe marked this conversation as resolved.
Show resolved Hide resolved
// I'm so sorry
split := strings.Split(n.Subject.URL, "/")
fetched <- StatusItem{
Repository: n.Repository.FullName,
Identifier: fmt.Sprintf("%s#%s", n.Repository.FullName, split[len(split)-1]),
preview: actual,
preview: preview,
rwe marked this conversation as resolved.
Show resolved Hide resolved
index: n.index,
}
} else if err != nil {
var httpErr api.HTTPError
if errors.As(err, &httpErr) && httpErr.StatusCode == 403 {
s.addAuthError(httpErr.Message, factory.SSOURL())
} else {
abortFetching()
return fmt.Errorf("could not fetch comment: %w", err)
}
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions pkg/cmd/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,63 @@ func TestStatusRun(t *testing.T) {
warning: You don't have permission to access this resource.
`),
},
{
name: "not found errors",
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.GraphQL("UserCurrent"),
httpmock.StringResponse(`{"data": {"viewer": {"login": "jillvalentine"}}}`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I enjoy Resident Evil, too 🧟

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 Didn't catch the reference, actually! Just based on the surrounding stubs.

reg.Register(
httpmock.REST("GET", "repos/rpd/todo/issues/110"),
httpmock.StringResponse(`{"body":"hello @jillvalentine how are you"}`))
reg.Register(
httpmock.REST("GET", "repos/rpd/todo/issues/4113"),
httpmock.StringResponse(`{"body":"this is a comment"}`))
reg.Register(
httpmock.REST("GET", "repos/cli/cli/issues/1096"),
httpmock.StringResponse(`{"body":"@jillvalentine hi"}`))
reg.Register(
httpmock.REST("GET", "repos/rpd/todo/issues/comments/1065"),
httpmock.StatusStringResponse(404, `{
"message": "Not Found."
}`))
reg.Register(
httpmock.REST("GET", "repos/vilmibm/gh-screensaver/issues/comments/10"),
httpmock.StringResponse(`{"body":"a message for @jillvalentine"}`))
reg.Register(
httpmock.GraphQL("AssignedSearch"),
httpmock.FileResponse("./fixtures/search.json"))
reg.Register(
httpmock.REST("GET", "notifications"),
httpmock.FileResponse("./fixtures/notifications.json"))
reg.Register(
httpmock.REST("GET", "users/jillvalentine/received_events"),
httpmock.FileResponse("./fixtures/events.json"))
},
opts: &StatusOptions{},
wantOut: heredoc.Doc(`
Assigned Issues │ Assigned Pull Requests
vilmibm/testing#157 yolo │ cli/cli#5272 Pin extensions
cli/cli#3223 Repo garden...│ rpd/todo#73 Board up RPD windows
rpd/todo#514 Reducing zo...│ cli/cli#4768 Issue Frecency
vilmibm/testing#74 welp │
adreyer/arkestrator#22 complete mo...│
Review Requests │ Mentions
cli/cli#5272 Pin extensions │ rpd/todo#110 hello @j...
vilmibm/testing#1234 Foobar │ cli/cli#1096 @jillval...
rpd/todo#50 Welcome party...│ rpd/todo#116 (could n...
cli/cli#4671 This pull req...│ vilmibm/gh-screensaver#15 a messag...
rpd/todo#49 Haircut for Leon│
Repository Activity
rpd/todo#5326 new PR Only write UTF-8 BOM on W...
vilmibm/testing#5325 comment on Ability to sea... We are working on dedicat...
cli/cli#5319 comment on [Codespaces] D... Wondering if we shouldn't...
cli/cli#5300 new issue Terminal bell when a runn...

`),
},
{
name: "notification errors",
httpStubs: func(reg *httpmock.Registry) {
Expand Down