Skip to content

Commit 5576ef0

Browse files
feat: wire announcement api (backport #4615) (#4620)
* feat: wire announcement api (#4615) (cherry picked from commit dd78fcb) # Conflicts: # ignite/cmd/cmd.go * fixes --------- Co-authored-by: julienrbrt <[email protected]>
1 parent f941a77 commit 5576ef0

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## Features
6+
7+
- [#4615](https://github.com/ignite/cli/pull/4615) Fetch Ignite announcements from API.
8+
59
## Changes
610

711
- [#4586](https://github.com/ignite/cli/pull/4586) Remove network as default plugin.

ignite/cmd/bubblemodel/chain_serve.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (m ChainServe) renderQuitView() string {
261261
}
262262

263263
fmt.Fprintf(&view, "%s %s\n", icons.Info, colors.Info("Stopped"))
264-
view.WriteString(announcements.GetAnnouncements())
264+
view.WriteString(announcements.Fetch())
265265

266266
return view.String()
267267
}

ignite/cmd/cmd.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ignitecmd
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"path/filepath"
78
"slices"
@@ -12,6 +13,7 @@ import (
1213
flag "github.com/spf13/pflag"
1314

1415
"github.com/ignite/cli/v28/ignite/config"
16+
"github.com/ignite/cli/v28/ignite/pkg/announcements"
1517
"github.com/ignite/cli/v28/ignite/pkg/cache"
1618
"github.com/ignite/cli/v28/ignite/pkg/cliui"
1719
uilog "github.com/ignite/cli/v28/ignite/pkg/cliui/log"
@@ -49,14 +51,17 @@ func New(ctx context.Context) (*cobra.Command, func(), error) {
4951
c := &cobra.Command{
5052
Use: "ignite",
5153
Short: "Ignite CLI offers everything you need to scaffold, test, build, and launch your blockchain",
52-
Long: `Ignite CLI is a tool for creating sovereign blockchains built with Cosmos SDK, the world's
54+
Long: fmt.Sprintf(`Ignite CLI is a tool for creating sovereign blockchains built with Cosmos SDK, the world's
5355
most popular modular blockchain framework. Ignite CLI offers everything you need to scaffold,
5456
test, build, and launch your blockchain.
5557
5658
To get started, create a blockchain:
5759
58-
ignite scaffold chain example
59-
`,
60+
$ ignite scaffold chain example
61+
62+
Announcements:
63+
%s
64+
`, announcements.Fetch()),
6065
SilenceUsage: true,
6166
SilenceErrors: true,
6267
Args: cobra.MinimumNArgs(0), // note(@julienrbrt): without this, ignite __complete(noDesc) hidden commands are not working.

ignite/pkg/announcements/announcement.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,49 @@ import (
55
"fmt"
66
"net/http"
77
"strings"
8+
"time"
89

910
"github.com/ignite/cli/v28/ignite/pkg/cliui/icons"
1011
)
1112

1213
var (
13-
SurveyLink = "https://bit.ly/3WZS2uS"
14-
AnnouncementAPI = "http://api.ignite.com/announcements"
14+
SurveyLink = "https://bit.ly/3WZS2uS"
15+
APIURL = "http://announcements.ignite.com/v1/announcements"
1516
)
1617

18+
type api struct {
19+
Announcements []announcement `json:"announcements"`
20+
}
21+
1722
type announcement struct {
18-
Announcements []string `json:"announcements"`
23+
ID string `json:"id"`
24+
Text string `json:"text"`
25+
Timestamp time.Time `json:"timestamp"`
26+
User string `json:"user"`
1927
}
2028

21-
func GetAnnouncements() string {
22-
resp, err := http.Get(AnnouncementAPI) //nolint:gosec
29+
// Fetch fetches the latest announcements from the API.
30+
func Fetch() string {
31+
resp, err := http.Get(APIURL) //nolint:gosec
2332
if err != nil || resp.StatusCode != 200 {
2433
return fallbackData()
2534
}
2635
defer resp.Body.Close()
2736

28-
var data announcement
37+
var data api
2938
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
3039
return fallbackData()
3140
}
3241

33-
// is this needed? or if its empty we don't want to show anything?
3442
if len(data.Announcements) == 0 {
3543
return fallbackData()
3644
}
3745

3846
var out strings.Builder
3947
fmt.Fprintf(&out, "\n%s %s\n", icons.Announcement, "Announcements")
4048

41-
for _, announcement := range data.Announcements {
42-
fmt.Fprintf(&out, "%s %s\n", icons.Bullet, announcement)
49+
for _, msg := range data.Announcements {
50+
fmt.Fprintf(&out, "%s %s\n", icons.Bullet, msg.Text)
4351
}
4452

4553
return out.String()

ignite/pkg/announcements/announcement_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/ignite/cli/v28/ignite/pkg/announcements"
1010
)
1111

12-
func TestGetAnnouncements(t *testing.T) {
12+
func TestFetchAnnouncements(t *testing.T) {
1313
fallbackData := fmt.Sprintf("\n💬 Survey: %s\n", announcements.SurveyLink)
1414

1515
tests := []struct {
@@ -20,9 +20,9 @@ func TestGetAnnouncements(t *testing.T) {
2020
}{
2121
{
2222
name: "successful retrieval",
23-
mockResponse: `{"announcements":["Announcement 1","Announcement 2"]}`,
23+
mockResponse: `{"version":1,"announcements":[{"id":"1744230503810","text":"New Ignite announcement: v1.0.0 released!","timestamp":"2025-04-09T20:28:23.810Z","user":"announcement-bot"}]}`,
2424
statusCode: http.StatusOK,
25-
expected: "\n🗣️ Announcements\nAnnouncement 1\n⋆ Announcement 2\n",
25+
expected: "\n🗣️ Announcements\nNew Ignite announcement: v1.0.0 released!\n",
2626
},
2727
{
2828
name: "empty announcements",
@@ -52,11 +52,11 @@ func TestGetAnnouncements(t *testing.T) {
5252
}))
5353
defer server.Close()
5454

55-
originalAPI := announcements.AnnouncementAPI
56-
announcements.AnnouncementAPI = server.URL
57-
defer func() { announcements.AnnouncementAPI = originalAPI }()
55+
originalAPI := announcements.APIURL
56+
announcements.APIURL = server.URL
57+
defer func() { announcements.APIURL = originalAPI }()
5858

59-
result := announcements.GetAnnouncements()
59+
result := announcements.Fetch()
6060
if result != tt.expected {
6161
t.Errorf("expected %q, got %q", tt.expected, result)
6262
}

0 commit comments

Comments
 (0)