Skip to content

Commit

Permalink
Release v1
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Mar 4, 2024
1 parent 8a55f6a commit 2d2402e
Show file tree
Hide file tree
Showing 15 changed files with 660 additions and 35 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
17 changes: 17 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Dependabot auto-merge

on: pull_request

permissions:
contents: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test
on:
push:
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: true

- name: Install dependencies
run: make init

- name: Lint
run: make lint-check

- name: check-is-dirty
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "Detected uncommitted changes."
git status
git diff
exit 1
fi
- name: Run tests
run: make test
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: goreleaser

on:
release:
types: [released, prereleased]

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: true

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

./fork-sweeper
.DS_Store
53 changes: 53 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- "386"
main: ./cmd/fork-sweeper

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}_{{ .Version }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

checksum:
name_template: "checksums.txt"

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

brews:
- name: link-patrol
homepage: "https://github.com/rednafi/fork-sweeper"
description: Remove unused GitHub forks
repository:
owner: rednafi
name: fork-sweeper
commit_author:
name: rednafi
email: [email protected]
15 changes: 15 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public/
static/
layouts/
themes/

# Ignore
**/*.html
**/Makefile
.editorconfig
.prettierignore
.git*
.hugo*
Brew*
pyproject*
requirements*
24 changes: 24 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"proseWrap": "preserve",
"semi": false,
"singleQuote": false,
"useTabs": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 92,
"overrides": [
{
"files": "**/*.md",
"options": {
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"trailingComma": "all",
"arrowParens": "avoid",
"printWidth": 92,
"proseWrap": "always",
"embeddedLanguageFormatting": "off"
}
}
]
}
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.PHONY: all build clean test lint ci

# Binary name for the output binary
BINARY_NAME=fork-sweeper

# Default command to run when no arguments are provided to make
all: build

# Builds the binary
build:
@echo "Building..."
go build -C cmd/fork-sweeper -o ../../${BINARY_NAME}

# Cleans our project: deletes binaries
clean:
@echo "Cleaning..."
go clean
rm -f ${BINARY_NAME}

# Runs tests
test:
@echo "Running tests..."
go test ./... -cover

# Lints the project
lint:
@echo "Linting..."
go fmt ./...
go vet ./...
go mod tidy

# Command for Continuous Integration
ci: lint test
@echo "CI steps..."
# Add commands specific to your CI setup
# e.g., integration testing, deployment commands, etc.

# Additional commands can be added below for database migrations, Docker operations, etc.
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<div align="center">
<pre align="center">
<h1 align="center">
fork
sweeper
|
\|/
-|-
// \\
/// \\\
//// \\\\
</h1>
<h4 align="center">
Remove unused GitHub forks
</h4>
</pre>
</div>

## Installation

- On macOS, brew install:

```sh
brew install fork-sweeper
```

- Elsewhere, go install:

```sh
go install fork-sweeper
```

## Prerequisites

- Collect your GitHub API [access token]. The token will be sent as `Bearer <token>` in
the HTTP header while making API requests.
- The token must have write and delete access to the forked repos.
- Set the `GITHUB_TOKEN` to your current shell environment with
`export GITHUB_TOKEN=<token>` command.

## Usage

- Run help:

```sh
fork-sweeper -h
```

```txt
Usage of fork-sweeper:
-delete
Delete forked repos
-max-page int
Maximum page number to fetch (default 100)
-older-than-days int
Delete forked repos older than this number of days (default 60)
-owner string
GitHub repo owner (required)
-per-page int
Number of forked repos fetched per page (default 100)
-token string
GitHub access token (required)
-version
```

- List forked repos older than `n` days. By default it'll fetch all reposties that were
forked at least 60 days ago.
```sh
fork-sweeper --owner rednafi --token $GITHUB_TOKEN --older-than-days 60
```
- The CLI won't delete any repository unless you explicitly tell it to do so with the
`--delete` flag:

```sh
fork-sweeper --owner rednafi --token $GITHUB_TOKEN --delete
```

[access token]:
https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28
10 changes: 0 additions & 10 deletions cmd/fork-pruner/main.go

This file was deleted.

19 changes: 19 additions & 0 deletions cmd/fork-sweeper/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"github.com/rednafi/fork-sweeper/src"
"os"
"text/tabwriter"
)

// Ldflags filled by goreleaser
var version = "dev"

func main() {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
defer w.Flush()

cliConfig := src.NewCLIConfig(w, version, os.Exit)

cliConfig.CLI(os.Args[1:])
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/rednafi/fork-pruner
module github.com/rednafi/fork-sweeper

go 1.22.0
Loading

0 comments on commit 2d2402e

Please sign in to comment.