Skip to content

Commit 0aeabb5

Browse files
authored
Merge pull request #30 from gomicro/better-output
Better output
2 parents 315c24a + 065b52f commit 0aeabb5

File tree

23 files changed

+547
-312
lines changed

23 files changed

+547
-312
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Build
2+
23
on: [push]
34

5+
env:
6+
GO_VERSION: '1.23'
7+
GOLANG_CI_VERSION: '1.61'
8+
49
jobs:
510

611
linting:
@@ -9,27 +14,28 @@ jobs:
914

1015
steps:
1116
- name: Checkout
12-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1318
with:
1419
fetch-depth: 0
1520

16-
- name: golangci-lint
17-
uses: golangci/golangci-lint-action@v3
21+
- uses: golangci/golangci-lint-action@v6
22+
name: "GolangCI-Lint ${{ env.GOLANG_CI_VERSION }}"
1823
with:
19-
version: latest
24+
version: v${{ env.GOLANG_CI_VERSION }}
25+
args: --timeout=5m
2026

2127
test:
2228
name: Test
2329
runs-on: ubuntu-latest
2430

2531
steps:
2632
- name: Install Go
27-
uses: actions/setup-go@v4
33+
uses: actions/setup-go@v5
2834
with:
29-
go-version: "1.21"
35+
go-version: ${{ env.GO_VERSION }}
3036

3137
- name: Checkout
32-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
3339
with:
3440
fetch-depth: 0
3541

@@ -48,12 +54,12 @@ jobs:
4854

4955
steps:
5056
- name: Install Go
51-
uses: actions/setup-go@v4
57+
uses: actions/setup-go@v5
5258
with:
53-
go-version: "1.21"
59+
go-version: ${{ env.GO_VERSION }}
5460

5561
- name: Checkout
56-
uses: actions/checkout@v3
62+
uses: actions/checkout@v4
5763
with:
5864
fetch-depth: 0
5965

@@ -65,15 +71,15 @@ jobs:
6571
password: ${{ secrets.GITHUB_TOKEN }}
6672

6773
- name: Snapshot
68-
uses: goreleaser/goreleaser-action@v5
74+
uses: goreleaser/goreleaser-action@v6
6975
with:
7076
distribution: goreleaser
7177
version: latest
7278
args: release --snapshot
7379

7480
- name: Release
7581
if: startsWith(github.ref, 'refs/tags/')
76-
uses: goreleaser/goreleaser-action@v5
82+
uses: goreleaser/goreleaser-action@v6
7783
with:
7884
distribution: goreleaser
7985
version: latest

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Gomicro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

client/client.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9+
"os"
910

10-
"github.com/gomicro/concord/report"
11+
"github.com/gomicro/scribe"
12+
"github.com/gomicro/scribe/color"
1113
"github.com/gomicro/trust"
1214
"github.com/google/go-github/v56/github"
1315
"golang.org/x/oauth2"
@@ -77,15 +79,22 @@ func (c *Client) Apply() error {
7779
return nil
7880
}
7981

80-
report.Println()
81-
report.PrintHeader("Applying")
82-
report.Println()
82+
t := &scribe.Theme{
83+
Describe: func(s string) string {
84+
return color.CyanFg(s)
85+
},
86+
Print: scribe.NoopDecorator,
87+
}
88+
89+
scrb := scribe.NewScribe(os.Stdout, t)
90+
91+
scrb.BeginDescribe("Applying")
92+
scrb.EndDescribe()
8393

8494
for _, fn := range c.stack {
8595
err := fn()
8696
if err != nil {
87-
report.PrintError(err.Error())
88-
report.Println()
97+
scrb.Print(color.RedFg(err.Error()))
8998
}
9099
}
91100

client/orgs.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"fmt"
77
"net/http"
88

9-
"github.com/gomicro/concord/report"
9+
"github.com/gomicro/scribe"
10+
"github.com/gomicro/scribe/color"
1011
"github.com/google/go-github/v56/github"
1112
)
1213

@@ -60,11 +61,8 @@ func (c *Client) GetMembers(ctx context.Context, orgName string) ([]*github.User
6061
return members, nil
6162
}
6263

63-
func (c *Client) InviteMember(ctx context.Context, orgName string, username string) {
64-
cs := &report.ChangeSet{}
65-
66-
cs.Add("invite "+username, "invited "+username)
67-
cs.PrintPre()
64+
func (c *Client) InviteMember(ctx context.Context, scrb scribe.Scriber, orgName string, username string) {
65+
scrb.Print(color.GreenFg("invite " + username))
6866

6967
c.Add(func() error {
7068
user, resp, err := c.ghClient.Users.Get(ctx, username)
@@ -91,13 +89,13 @@ func (c *Client) InviteMember(ctx context.Context, orgName string, username stri
9189
return err
9290
}
9391

94-
cs.PrintPost()
92+
scrb.Print(color.GreenFg("invited " + username))
9593

9694
return nil
9795
})
9896
}
9997

100-
func (c *Client) SetOrgPrivileges(ctx context.Context, orgName string, edits *github.Organization) error {
98+
func (c *Client) SetOrgPrivileges(ctx context.Context, scrb scribe.Scriber, orgName string, edits *github.Organization) error {
10199
ghOrg, _, err := c.ghClient.Organizations.Get(ctx, orgName)
102100
if err != nil {
103101
if _, ok := err.(*github.RateLimitError); ok {
@@ -113,31 +111,24 @@ func (c *Client) SetOrgPrivileges(ctx context.Context, orgName string, edits *gi
113111
return err
114112
}
115113

116-
cs := &report.ChangeSet{}
117-
114+
base := false
118115
if edits.DefaultRepoPermission != nil && *edits.DefaultRepoPermission != *ghOrg.DefaultRepoPermission {
119-
cs.Add(
120-
fmt.Sprintf("setting base permissions to '%s'", *edits.DefaultRepoPermission),
121-
fmt.Sprintf("set base permissions to '%s'", *edits.DefaultRepoPermission),
122-
)
116+
scrb.Print(color.GreenFg(fmt.Sprintf("setting base permissions to '%s'", *edits.DefaultRepoPermission)))
117+
base = true
123118
}
124119

120+
prvRepos := false
125121
if edits.MembersCanCreatePrivateRepos != nil && *edits.MembersCanCreatePrivateRepos != *ghOrg.MembersCanCreatePrivateRepos {
126-
cs.Add(
127-
fmt.Sprintf("setting private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos),
128-
fmt.Sprintf("set private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos),
129-
)
122+
scrb.Print(color.GreenFg(fmt.Sprintf("setting private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos)))
123+
prvRepos = true
130124
}
131125

126+
pubRepos := false
132127
if edits.MembersCanCreatePublicRepos != nil && *edits.MembersCanCreatePublicRepos != *ghOrg.MembersCanCreatePublicRepos {
133-
cs.Add(
134-
fmt.Sprintf("setting public repo creation to '%t'", *edits.MembersCanCreatePublicRepos),
135-
fmt.Sprintf("set public repo creation to '%t'", *edits.MembersCanCreatePublicRepos),
136-
)
128+
scrb.Print(color.GreenFg(fmt.Sprintf("setting public repo creation to '%t'", *edits.MembersCanCreatePublicRepos)))
129+
pubRepos = true
137130
}
138131

139-
cs.PrintPre()
140-
141132
c.Add(func() error {
142133
_, resp, err := c.ghClient.Organizations.Edit(ctx, orgName, edits)
143134
if err != nil {
@@ -152,7 +143,17 @@ func (c *Client) SetOrgPrivileges(ctx context.Context, orgName string, edits *gi
152143
return err
153144
}
154145

155-
cs.PrintPost()
146+
if base {
147+
scrb.Print(color.GreenFg(fmt.Sprintf("set base permissions to '%s'", *edits.DefaultRepoPermission)))
148+
}
149+
150+
if prvRepos {
151+
scrb.Print(color.GreenFg(fmt.Sprintf("set private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos)))
152+
}
153+
154+
if pubRepos {
155+
scrb.Print(color.GreenFg(fmt.Sprintf("set public repo creation to '%t'", *edits.MembersCanCreatePublicRepos)))
156+
}
156157

157158
return nil
158159
})

0 commit comments

Comments
 (0)