Skip to content

Commit

Permalink
Merge branch 'beta' into feat/generate-config-yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
zeucapua authored Sep 9, 2024
2 parents 852cd61 + 7f05182 commit 6e4f357
Show file tree
Hide file tree
Showing 55 changed files with 2,113 additions and 148 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Env vars used in the justfile during buildtime

POSTHOG_PUBLIC_API_KEY="phc_Y0xz6nK55MEwWjobJsI2P8rsiomZJ6eZLoXehmMy9tt"
16 changes: 16 additions & 0 deletions .github/workflows/pizza.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: OpenSauced Pizza Action

on:
schedule:
# Run once a week on Sunday at 00:00 UTC
- cron: "0 0 * * 0"
workflow_dispatch: # Allow manual triggering

jobs:
pizza-action:
runs-on: ubuntu-latest
steps:
- name: Pizza Action
uses: open-sauced/[email protected]
with:
commit-and-pr: "true"
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
version: v1.60

test:
runs-on: ubuntu-latest
Expand Down
15 changes: 13 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
linters:
enable:
- asasalint
- asciicheck
- bidichk
- canonicalheader
- errcheck
- gci
- goimports
- gocritic
- gosec
- govet
- ineffassign
- misspell
- revive
- perfsprint
- staticcheck
- unconvert
- unused
- govet
- gci
- testifylint

linters-settings:
gci:
Expand All @@ -23,3 +31,6 @@ linters-settings:

run:
timeout: 5m

# attempts to automatically fix linting errors that are fixable by supported linters
fix: true
2 changes: 2 additions & 0 deletions .sauced.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ attribution:
nickytonline:
- [email protected]
- [email protected]
zeucapua:
- [email protected]

75 changes: 75 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,81 @@

> All notable changes to this project will be documented in this file
## [1.3.1-beta.2](https://github.com/open-sauced/pizza-cli/compare/v1.3.1-beta.1...v1.3.1-beta.2) (2024-09-06)


### 🐛 Bug Fixes

* use the local directory and home directory as fallback for .sauced.yaml ([#158](https://github.com/open-sauced/pizza-cli/issues/158)) ([af2f361](https://github.com/open-sauced/pizza-cli/commit/af2f3612e26634455602d1840714c5bf15e1e40a))

## [1.3.1-beta.1](https://github.com/open-sauced/pizza-cli/compare/v1.3.0...v1.3.1-beta.1) (2024-09-06)


### 🐛 Bug Fixes

* skip interactive steps in generate codeowners with --tty-disable flag ([#159](https://github.com/open-sauced/pizza-cli/issues/159)) ([49f1fd3](https://github.com/open-sauced/pizza-cli/commit/49f1fd3fc4df24b95724feb1918dc80276cd017e))

## [1.3.0](https://github.com/open-sauced/pizza-cli/compare/v1.2.1...v1.3.0) (2024-09-06)


### 🍕 Features

* Create a contributor list after generating codeowners ([#141](https://github.com/open-sauced/pizza-cli/issues/141)) ([72c5d58](https://github.com/open-sauced/pizza-cli/commit/72c5d588fcd4fb04f6d39d756a6a26a47d25a4e4))
* now the documentation for the pizza-cli can be generated via pizza docs ([#143](https://github.com/open-sauced/pizza-cli/issues/143)) ([3f5d27e](https://github.com/open-sauced/pizza-cli/commit/3f5d27e2c52c894a266828e70e7475069e74e8e9))
* Refactors API client into hand rolled sdk in api/ directory ([#111](https://github.com/open-sauced/pizza-cli/issues/111)) ([e16e889](https://github.com/open-sauced/pizza-cli/commit/e16e8899a4ef69641dc614887d065dc8b70adb35))
* support fallback attributions when generating codeowners file ([#145](https://github.com/open-sauced/pizza-cli/issues/145)) ([35af4da](https://github.com/open-sauced/pizza-cli/commit/35af4dafc4ed088ba1396ff28e1536723c914a2b))
* update `CODEOWNERS` copy with command ([#130](https://github.com/open-sauced/pizza-cli/issues/130)) ([a477959](https://github.com/open-sauced/pizza-cli/commit/a477959020cfcbb3dc4707efb1700e17e05e3981))


### 🐛 Bug Fixes

* Corrects invalid gosec lint error ([#151](https://github.com/open-sauced/pizza-cli/issues/151)) ([f76527f](https://github.com/open-sauced/pizza-cli/commit/f76527f0c61c5720f684416f391fe1395774e1fb))
* Exhume Posthog functionality ([#147](https://github.com/open-sauced/pizza-cli/issues/147)) ([de091ca](https://github.com/open-sauced/pizza-cli/commit/de091cac7df585eadcfae64d6f851cfc178c74a2))
* now fallback .sauced.yaml contents get read ([#135](https://github.com/open-sauced/pizza-cli/issues/135)) ([fd658e5](https://github.com/open-sauced/pizza-cli/commit/fd658e5e09051cdf007c3605aa880d68db835afb))
* NPM cache now looks at package-lock file ([#136](https://github.com/open-sauced/pizza-cli/issues/136)) ([cd4b8da](https://github.com/open-sauced/pizza-cli/commit/cd4b8da75e1a0c0aa3d7e6f76d6b560a4dea941f))

## [1.3.0-beta.9](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.8...v1.3.0-beta.9) (2024-09-06)


### 🐛 Bug Fixes

* Corrects invalid gosec lint error ([#151](https://github.com/open-sauced/pizza-cli/issues/151)) ([f76527f](https://github.com/open-sauced/pizza-cli/commit/f76527f0c61c5720f684416f391fe1395774e1fb))

## [1.3.0-beta.8](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.7...v1.3.0-beta.8) (2024-09-06)


### 🍕 Features

* now the documentation for the pizza-cli can be generated via pizza docs ([#143](https://github.com/open-sauced/pizza-cli/issues/143)) ([3f5d27e](https://github.com/open-sauced/pizza-cli/commit/3f5d27e2c52c894a266828e70e7475069e74e8e9))

## [1.3.0-beta.7](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.6...v1.3.0-beta.7) (2024-09-06)


### 🐛 Bug Fixes

* Exhume Posthog functionality ([#147](https://github.com/open-sauced/pizza-cli/issues/147)) ([de091ca](https://github.com/open-sauced/pizza-cli/commit/de091cac7df585eadcfae64d6f851cfc178c74a2))

## [1.3.0-beta.6](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.5...v1.3.0-beta.6) (2024-09-05)


### 🍕 Features

* support fallback attributions when generating codeowners file ([#145](https://github.com/open-sauced/pizza-cli/issues/145)) ([35af4da](https://github.com/open-sauced/pizza-cli/commit/35af4dafc4ed088ba1396ff28e1536723c914a2b))

## [1.3.0-beta.5](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.4...v1.3.0-beta.5) (2024-09-05)


### 🍕 Features

* Create a contributor list after generating codeowners ([#141](https://github.com/open-sauced/pizza-cli/issues/141)) ([72c5d58](https://github.com/open-sauced/pizza-cli/commit/72c5d588fcd4fb04f6d39d756a6a26a47d25a4e4))

## [1.3.0-beta.4](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.3...v1.3.0-beta.4) (2024-09-05)


### 🐛 Bug Fixes

* now fallback .sauced.yaml contents get read ([#135](https://github.com/open-sauced/pizza-cli/issues/135)) ([fd658e5](https://github.com/open-sauced/pizza-cli/commit/fd658e5e09051cdf007c3605aa880d68db835afb))

## [1.3.0-beta.3](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.2...v1.3.0-beta.3) (2024-09-04)


Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ARG BUILDPLATFORM
ARG VERSION
ARG SHA
ARG DATETIME
ARG POSTHOG_PUBLIC_API_KEY

# Get the dependencies downloaded
WORKDIR /app
Expand All @@ -17,7 +18,8 @@ COPY . ./
RUN go build -ldflags="-s -w \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${VERSION}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=${SHA}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}'" \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.Datetime=${DATETIME}' \
-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${POSTHOG_PUBLIC_API_KEY}'" \
-o pizza .

# Runner layer
Expand Down
32 changes: 22 additions & 10 deletions api/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
_ "embed" // global import of embed to enable the use of the "go embed" directive
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand All @@ -33,8 +34,8 @@ const (
codeChallengeLength = 87
sessionFileName = "session.json"

prodSupabaseURL = "https://fcqqkxwlntnrtjfbcioz.supabase.co"
prodSupabasePublicKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZjcXFreHdsbnRucnRqZmJjaW96Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTg0MTkyNzQsImV4cCI6MjAxMzk5NTI3NH0.ymWWYdnJC2gsnrJx4lZX2cfSOp-1xVuWFGt1Wr6zwtg"
prodSupabaseURL = "https://ibcwmlhcimymasokhgvn.supabase.co"
prodSupabasePublicKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImliY3dtbGhjaW15bWFzb2toZ3ZuIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTkyOTU1MzMsImV4cCI6MjAxNDg3MTUzM30.Mr-ucuNDBjy9BC7NJzOBBi0Qz8WYiKI4n0JtWr4_woY"

// TODO (jpmcb) - in the future, we'll want to encorporate the ability to
// authenticate to our beta auth service as well
Expand Down Expand Up @@ -64,7 +65,7 @@ func NewAuthenticator() *Authenticator {
// local server for handling the login. Once the server has completed and received
// the session, the server is shut down and control is returned back to the CLI.
func (a *Authenticator) Login() (string, error) {
supabaseAuthURL := fmt.Sprintf("%s/auth/v1/authorize", prodSupabaseURL)
supabaseAuthURL := prodSupabaseURL + "/auth/v1/authorize"

// 1. Generate the PKCE
codeVerifier, codeChallenge, err := a.generatePkce(codeChallengeLength)
Expand All @@ -79,8 +80,9 @@ func (a *Authenticator) Login() (string, error) {
r.Get("/", a.handleLocalCallback)

server := &http.Server{
Addr: authCallbackAddr,
Handler: r,
Addr: authCallbackAddr,
Handler: r,
ReadHeaderTimeout: time.Second * 5,
}

go func() {
Expand Down Expand Up @@ -112,7 +114,7 @@ func (a *Authenticator) Login() (string, error) {
a.shutdownServer(server)
case <-time.After(60 * time.Second):
a.shutdownServer(server)
return "", fmt.Errorf("authentication timeout")
return "", errors.New("authentication timeout")
}

return a.username, nil
Expand All @@ -124,7 +126,7 @@ func (a *Authenticator) handleLocalCallback(w http.ResponseWriter, r *http.Reque
code := r.URL.Query().Get("code")
if code == "" {
http.Error(w, "'code' query param not found", http.StatusBadRequest)
a.errChan <- fmt.Errorf("'code' query param not found")
a.errChan <- errors.New("'code' query param not found")
return
}

Expand Down Expand Up @@ -171,12 +173,22 @@ func (a *Authenticator) CheckSession() error {

// Check if session is expired or about to expire (within 5 minutes)
if time.Now().Add(5 * time.Minute).After(time.Unix(session.ExpiresAt, 0)) {
return fmt.Errorf("session expired")
return errors.New("session expired")
}

return nil
}

// GetSessionToken returns the access token for a given session
func (a *Authenticator) GetSessionToken() (string, error) {
session, err := a.readSessionFile()
if err != nil {
return "", fmt.Errorf("failed to read session file: %w", err)
}

return session.AccessToken, nil
}

// readSessionFile reads a session file and returns the session struct.
func (a *Authenticator) readSessionFile() (*session, error) {
configDir, err := config.GetConfigDirectory()
Expand Down Expand Up @@ -223,7 +235,7 @@ func (a *Authenticator) generatePkce(length int) (string, string, error) {
// getSession takes an authentication code and a verifier, using the Supabase
// auth service, to get a session
func (a *Authenticator) getSession(authCode, codeVerifier string) (*session, error) {
url := fmt.Sprintf("%s/auth/v1/token?grant_type=pkce", prodSupabaseURL)
url := prodSupabaseURL + "/auth/v1/token?grant_type=pkce"

payload := map[string]string{
"auth_code": authCode,
Expand All @@ -234,7 +246,7 @@ func (a *Authenticator) getSession(authCode, codeVerifier string) (*session, err

req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload))
req.Header.Set("Content-Type", "application/json;charset=UTF-8")
req.Header.Set("ApiKey", prodSupabasePublicKey)
req.Header.Set("Apikey", prodSupabasePublicKey)

res, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/open-sauced/pizza-cli/api/services/contributors"
"github.com/open-sauced/pizza-cli/api/services/histogram"
"github.com/open-sauced/pizza-cli/api/services/repository"
"github.com/open-sauced/pizza-cli/api/services/workspaces"
)

// Client is the API client for OpenSauced API
Expand All @@ -15,6 +16,7 @@ type Client struct {
RepositoryService *repository.Service
ContributorService *contributors.Service
HistogramService *histogram.Service
WorkspacesService *workspaces.Service

// The configured http client for making API requests
httpClient *http.Client
Expand All @@ -40,6 +42,7 @@ func NewClient(endpoint string) *Client {
client.ContributorService = contributors.NewContributorsService(client.httpClient, client.endpoint)
client.RepositoryService = repository.NewRepositoryService(client.httpClient, client.endpoint)
client.HistogramService = histogram.NewHistogramService(client.httpClient, client.endpoint)
client.WorkspacesService = workspaces.NewWorkspacesService(client.httpClient, client.endpoint)

return &client
}
21 changes: 11 additions & 10 deletions api/services/contributors/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
)

Expand All @@ -25,7 +26,7 @@ func NewContributorsService(httpClient *http.Client, endpoint string) *Service {

// NewPullRequestContributors calls the "v2/contributors/insights/new" API endpoint
func (s *Service) NewPullRequestContributors(repos []string, rangeVal int) (*ContribResponse, *http.Response, error) {
baseURL := fmt.Sprintf("%s/v2/contributors/insights/new", s.endpoint)
baseURL := s.endpoint + "/v2/contributors/insights/new"

// Create URL with query parameters
u, err := url.Parse(baseURL)
Expand All @@ -34,7 +35,7 @@ func (s *Service) NewPullRequestContributors(repos []string, rangeVal int) (*Con
}

q := u.Query()
q.Set("range", fmt.Sprintf("%d", rangeVal))
q.Set("range", strconv.Itoa(rangeVal))
q.Set("repos", strings.Join(repos, ","))
u.RawQuery = q.Encode()

Expand All @@ -58,7 +59,7 @@ func (s *Service) NewPullRequestContributors(repos []string, rangeVal int) (*Con

// RecentPullRequestContributors calls the "v2/contributors/insights/recent" API endpoint
func (s *Service) RecentPullRequestContributors(repos []string, rangeVal int) (*ContribResponse, *http.Response, error) {
baseURL := fmt.Sprintf("%s/v2/contributors/insights/recent", s.endpoint)
baseURL := s.endpoint + "/v2/contributors/insights/recent"

// Create URL with query parameters
u, err := url.Parse(baseURL)
Expand All @@ -67,7 +68,7 @@ func (s *Service) RecentPullRequestContributors(repos []string, rangeVal int) (*
}

q := u.Query()
q.Set("range", fmt.Sprintf("%d", rangeVal))
q.Set("range", strconv.Itoa(rangeVal))
q.Set("repos", strings.Join(repos, ","))
u.RawQuery = q.Encode()

Expand All @@ -91,7 +92,7 @@ func (s *Service) RecentPullRequestContributors(repos []string, rangeVal int) (*

// AlumniPullRequestContributors calls the "v2/contributors/insights/alumni" API endpoint
func (s *Service) AlumniPullRequestContributors(repos []string, rangeVal int) (*ContribResponse, *http.Response, error) {
baseURL := fmt.Sprintf("%s/v2/contributors/insights/alumni", s.endpoint)
baseURL := s.endpoint + "/v2/contributors/insights/alumni"

// Create URL with query parameters
u, err := url.Parse(baseURL)
Expand All @@ -100,7 +101,7 @@ func (s *Service) AlumniPullRequestContributors(repos []string, rangeVal int) (*
}

q := u.Query()
q.Set("range", fmt.Sprintf("%d", rangeVal))
q.Set("range", strconv.Itoa(rangeVal))
q.Set("repos", strings.Join(repos, ","))
u.RawQuery = q.Encode()

Expand All @@ -124,7 +125,7 @@ func (s *Service) AlumniPullRequestContributors(repos []string, rangeVal int) (*

// RepeatPullRequestContributors calls the "v2/contributors/insights/repeat" API endpoint
func (s *Service) RepeatPullRequestContributors(repos []string, rangeVal int) (*ContribResponse, *http.Response, error) {
baseURL := fmt.Sprintf("%s/v2/contributors/insights/repeat", s.endpoint)
baseURL := s.endpoint + "/v2/contributors/insights/repeat"

// Create URL with query parameters
u, err := url.Parse(baseURL)
Expand All @@ -133,7 +134,7 @@ func (s *Service) RepeatPullRequestContributors(repos []string, rangeVal int) (*
}

q := u.Query()
q.Set("range", fmt.Sprintf("%d", rangeVal))
q.Set("range", strconv.Itoa(rangeVal))
q.Set("repos", strings.Join(repos, ","))
u.RawQuery = q.Encode()

Expand All @@ -157,7 +158,7 @@ func (s *Service) RepeatPullRequestContributors(repos []string, rangeVal int) (*

// SearchPullRequestContributors calls the "v2/contributors/search"
func (s *Service) SearchPullRequestContributors(repos []string, rangeVal int) (*ContribResponse, *http.Response, error) {
baseURL := fmt.Sprintf("%s/v2/contributors/search", s.endpoint)
baseURL := s.endpoint + "/v2/contributors/search"

// Create URL with query parameters
u, err := url.Parse(baseURL)
Expand All @@ -166,7 +167,7 @@ func (s *Service) SearchPullRequestContributors(repos []string, rangeVal int) (*
}

q := u.Query()
q.Set("range", fmt.Sprintf("%d", rangeVal))
q.Set("range", strconv.Itoa(rangeVal))
q.Set("repos", strings.Join(repos, ","))
u.RawQuery = q.Encode()

Expand Down
Loading

0 comments on commit 6e4f357

Please sign in to comment.