-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from open-sauced/beta
chore: release 2.3.0
- Loading branch information
Showing
13 changed files
with
395 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
</a> | ||
</div> | ||
|
||
# 📦 Install | ||
# 📦 [Install](#-install) | ||
|
||
#### Homebrew | ||
|
||
|
@@ -149,6 +149,78 @@ jobs: | |
how to use the Pizza command line tool and how it works with the rest of the OpenSauced | ||
ecosystem. | ||
# 🚀 Quickstart | ||
Get up and running with the Pizza CLI in minutes using `npx`: | ||
1. **Ensure you have Node.js installed** | ||
Pizza CLI can be run using `npx`, which comes with Node.js. If you don't have Node.js installed, download it from [nodejs.org](https://nodejs.org/). | ||
> NOTE | ||
> For other installation methods, see the [Install](#-Install) section. | ||
2. **Generate a configuration file** | ||
Navigate to your project directory and run: | ||
```sh | ||
npx pizza@latest generate config ./ -i | ||
``` | ||
This will create a `.sauced.yaml` file, interactively prompting you to attribute commit emails to GitHub handles. | ||
3. **Generate CODEOWNERS file** | ||
In your project directory, run: | ||
```sh | ||
npx pizza@latest generate codeowners ./ | ||
``` | ||
This will create a `CODEOWNERS` file based on your project's git history and the `.sauced.yaml` configuration. | ||
4. **Create OpenSauced [Contributor Insight](https://opensauced.pizza/docs/features/contributor-insights/)** | ||
After generating the CODEOWNERS file, you can create an OpenSauced Contributor Insight: | ||
```sh | ||
npx pizza@latest generate insight . | ||
``` | ||
5. **Explore repository insights** | ||
Get metrics and insights for your repository: | ||
```sh | ||
npx pizza@latest insights repositories your-username/your-repo | ||
``` | ||
6. **Set up automated CODEOWNERS updates (Optional)** | ||
Add the [Pizza GitHub Action](https://github.com/open-sauced/pizza-action) to your repository to automate CODEOWNERS updates: | ||
```yaml | ||
# In .github/workflows/pizza-action.yml | ||
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: | ||
# optional and default is "latest". Add this parameter if you want to use a specific version, e.g. v2.0.0 | ||
cli-version: "v2.2.0" | ||
# optional and false by default. Set this to true if you want to have a pull request for the changes created automatically. | ||
commit-and-pr: "true" | ||
# optional | ||
pr-title: "chore: update repository codeowners" | ||
``` | ||
Now you're ready to leverage the Pizza CLI for managing code ownership and getting project insights with OpenSauced! | ||
> Note | ||
> Using `npx pizza@latest` ensures you're always running the most recent version of Pizza CLI. If you prefer to use a specific version, you can replace `@latest` with a version number, e.g., `npx [email protected]`. | ||
# ✨ Usage | ||
## Codeowners generation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package offboard | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/open-sauced/pizza-cli/v2/pkg/config" | ||
"github.com/open-sauced/pizza-cli/v2/pkg/constants" | ||
"github.com/open-sauced/pizza-cli/v2/pkg/utils" | ||
) | ||
|
||
type Options struct { | ||
offboardingUsers []string | ||
|
||
// config file path | ||
configPath string | ||
|
||
// repository path | ||
path string | ||
|
||
// from global config | ||
ttyDisabled bool | ||
|
||
// telemetry for capturing CLI events via PostHog | ||
telemetry *utils.PosthogCliClient | ||
} | ||
|
||
const offboardLongDesc string = `CAUTION: Experimental Command. Removes users from the \".sauced.yaml\" config and \"CODEOWNERS\" files. | ||
Requires the users' name OR email.` | ||
|
||
func NewConfigCommand() *cobra.Command { | ||
opts := &Options{} | ||
cmd := &cobra.Command{ | ||
Use: "offboard <username/email> [flags]", | ||
Short: "CAUTION: Experimental Command. Removes users from the \".sauced.yaml\" config and \"CODEOWNERS\" files.", | ||
Long: offboardLongDesc, | ||
Args: func(_ *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New("you must provide at least one argument: the offboarding user's email/username") | ||
} | ||
|
||
opts.offboardingUsers = args | ||
|
||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
opts.ttyDisabled, _ = cmd.Flags().GetBool("tty-disable") | ||
opts.configPath, _ = cmd.Flags().GetString("config") | ||
disableTelem, _ := cmd.Flags().GetBool(constants.FlagNameTelemetry) | ||
|
||
opts.telemetry = utils.NewPosthogCliClient(!disableTelem) | ||
|
||
opts.path, _ = cmd.Flags().GetString("path") | ||
err := run(opts) | ||
_ = opts.telemetry.Done() | ||
|
||
return err | ||
}, | ||
} | ||
|
||
cmd.PersistentFlags().StringP("path", "p", "", "the path to the repository (required)") | ||
if err := cmd.MarkPersistentFlagRequired("path"); err != nil { | ||
fmt.Printf("error MarkPersistentFlagRequired: %v", err) | ||
} | ||
return cmd | ||
} | ||
|
||
func run(opts *Options) error { | ||
var spec *config.Spec | ||
var err error | ||
if len(opts.configPath) != 0 { | ||
spec, _, err = config.LoadConfig(opts.configPath) | ||
} else { | ||
var configPath string | ||
if strings.Compare(string(opts.path[len(opts.path)-1]), "/") == 0 { | ||
configPath = opts.path + ".sauced.yaml" | ||
} else { | ||
configPath = opts.path + "/.sauced.yaml" | ||
} | ||
spec, _, err = config.LoadConfig(configPath) | ||
} | ||
|
||
if err != nil { | ||
_ = opts.telemetry.CaptureFailedOffboard() | ||
return fmt.Errorf("error loading config: %v", err) | ||
} | ||
|
||
var offboardingNames []string | ||
attributions := spec.Attributions | ||
for _, user := range opts.offboardingUsers { | ||
added := false | ||
|
||
// deletes if the user is a name (key) | ||
delete(attributions, user) | ||
|
||
// delete if the user is an email (value) | ||
for k, v := range attributions { | ||
if slices.Contains(v, user) { | ||
offboardingNames = append(offboardingNames, k) | ||
delete(attributions, k) | ||
added = true | ||
} | ||
} | ||
|
||
if !added { | ||
offboardingNames = append(offboardingNames, user) | ||
} | ||
} | ||
|
||
if len(opts.configPath) != 0 { | ||
err = generateConfigFile(opts.configPath, attributions) | ||
} else { | ||
var configPath string | ||
if strings.Compare(string(opts.path[len(opts.path)-1]), "/") == 0 { | ||
configPath = opts.path + ".sauced.yaml" | ||
} else { | ||
configPath = opts.path + "/.sauced.yaml" | ||
} | ||
err = generateConfigFile(configPath, attributions) | ||
} | ||
|
||
if err != nil { | ||
_ = opts.telemetry.CaptureFailedOffboard() | ||
return fmt.Errorf("error generating config file: %v", err) | ||
} | ||
|
||
err = generateOwnersFile(opts.path, offboardingNames) | ||
if err != nil { | ||
_ = opts.telemetry.CaptureFailedOffboard() | ||
return fmt.Errorf("error generating owners file: %v", err) | ||
} | ||
|
||
_ = opts.telemetry.CaptureOffboard() | ||
return nil | ||
} |
Oops, something went wrong.