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
30 changes: 18 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Build

on: [push]

env:
GO_VERSION: '1.23'
GOLANG_CI_VERSION: '1.61'

jobs:

linting:
Expand All @@ -9,27 +14,28 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
- uses: golangci/golangci-lint-action@v6
name: "GolangCI-Lint ${{ env.GOLANG_CI_VERSION }}"
with:
version: latest
version: v${{ env.GOLANG_CI_VERSION }}
args: --timeout=5m

test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: ${{ env.GO_VERSION }}

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -48,12 +54,12 @@ jobs:

steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: ${{ env.GO_VERSION }}

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

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

- name: Snapshot
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --snapshot

- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Gomicro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 15 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"errors"
"fmt"
"net/http"
"os"

"github.com/gomicro/concord/report"
"github.com/gomicro/scribe"
"github.com/gomicro/scribe/color"
"github.com/gomicro/trust"
"github.com/google/go-github/v56/github"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -77,15 +79,22 @@ func (c *Client) Apply() error {
return nil
}

report.Println()
report.PrintHeader("Applying")
report.Println()
t := &scribe.Theme{
Describe: func(s string) string {
return color.CyanFg(s)
},
Print: scribe.NoopDecorator,
}

scrb := scribe.NewScribe(os.Stdout, t)

scrb.BeginDescribe("Applying")
scrb.EndDescribe()

for _, fn := range c.stack {
err := fn()
if err != nil {
report.PrintError(err.Error())
report.Println()
scrb.Print(color.RedFg(err.Error()))
}
}

Expand Down
51 changes: 26 additions & 25 deletions client/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"fmt"
"net/http"

"github.com/gomicro/concord/report"
"github.com/gomicro/scribe"
"github.com/gomicro/scribe/color"
"github.com/google/go-github/v56/github"
)

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

func (c *Client) InviteMember(ctx context.Context, orgName string, username string) {
cs := &report.ChangeSet{}

cs.Add("invite "+username, "invited "+username)
cs.PrintPre()
func (c *Client) InviteMember(ctx context.Context, scrb scribe.Scriber, orgName string, username string) {
scrb.Print(color.GreenFg("invite " + username))

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

cs.PrintPost()
scrb.Print(color.GreenFg("invited " + username))

return nil
})
}

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

cs := &report.ChangeSet{}

base := false
if edits.DefaultRepoPermission != nil && *edits.DefaultRepoPermission != *ghOrg.DefaultRepoPermission {
cs.Add(
fmt.Sprintf("setting base permissions to '%s'", *edits.DefaultRepoPermission),
fmt.Sprintf("set base permissions to '%s'", *edits.DefaultRepoPermission),
)
scrb.Print(color.GreenFg(fmt.Sprintf("setting base permissions to '%s'", *edits.DefaultRepoPermission)))
base = true
}

prvRepos := false
if edits.MembersCanCreatePrivateRepos != nil && *edits.MembersCanCreatePrivateRepos != *ghOrg.MembersCanCreatePrivateRepos {
cs.Add(
fmt.Sprintf("setting private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos),
fmt.Sprintf("set private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos),
)
scrb.Print(color.GreenFg(fmt.Sprintf("setting private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos)))
prvRepos = true
}

pubRepos := false
if edits.MembersCanCreatePublicRepos != nil && *edits.MembersCanCreatePublicRepos != *ghOrg.MembersCanCreatePublicRepos {
cs.Add(
fmt.Sprintf("setting public repo creation to '%t'", *edits.MembersCanCreatePublicRepos),
fmt.Sprintf("set public repo creation to '%t'", *edits.MembersCanCreatePublicRepos),
)
scrb.Print(color.GreenFg(fmt.Sprintf("setting public repo creation to '%t'", *edits.MembersCanCreatePublicRepos)))
pubRepos = true
}

cs.PrintPre()

c.Add(func() error {
_, resp, err := c.ghClient.Organizations.Edit(ctx, orgName, edits)
if err != nil {
Expand All @@ -152,7 +143,17 @@ func (c *Client) SetOrgPrivileges(ctx context.Context, orgName string, edits *gi
return err
}

cs.PrintPost()
if base {
scrb.Print(color.GreenFg(fmt.Sprintf("set base permissions to '%s'", *edits.DefaultRepoPermission)))
}

if prvRepos {
scrb.Print(color.GreenFg(fmt.Sprintf("set private repo creation to '%t'", *edits.MembersCanCreatePrivateRepos)))
}

if pubRepos {
scrb.Print(color.GreenFg(fmt.Sprintf("set public repo creation to '%t'", *edits.MembersCanCreatePublicRepos)))
}

return nil
})
Expand Down
Loading
Loading