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
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ Usage: spaid_pr_list \[-h\]

Lists all open PRs in an organization.

Examples: \$ spaid_pr_list seedcase-project
Examples:

spaid_pr_list seedcase-project

Positional argument:

Expand All @@ -122,23 +124,61 @@ spaid_pr_merge_rebase -h

Usage: spaid_pr_merge_rebase \[-h\]

Approve a PR and do a merge rebase on multiple PRs in a single
repository. Requires admin privilege, so not everyone can use this
command.
Approve and do a merge rebase on multiple PRs in a single repository.
Requires admin privilege, so not everyone can use this command.

Examples:

# Do merge rebase on (fake) PRs 1, 2, and 3.
$ spaid_pr_merge_rebase seedcase-project seedcase-theme 1 2 3
spaid_pr_merge_rebase seedcase-project seedcase-theme 1 2 3

Positional arguments:

- org: The name of the GitHub organization.
- repo: The name of the repository in the GitHub organization.
- PR number(s): One or more PR numbers to do the merge rebase for.

``` bash
spaid_pr_merge_chores -h
```

Usage: spaid_pr_merge_chores \[-h\]

Go through all open PRs in a GitHub organization (or optionally in only
one repo) and do a merge rebase on them if they contain the string
‘chore(sync):’ or ‘ci(pre-commit):’ in the title. Requires admin
privilege, so not everyone can use this command.

Examples:

spaid_pr_merge_chores seedcase-project

Positional arguments:

- org: Required. The name of the GitHub organization.
- repo: Optional. The name of the repository in the GitHub organization.
If not given, the command will run on all repositories in the
organization.

### GitHub organization management

``` bash
spaid_gh_repo_list -h
```

Usage: spaid_gh_repo_list \[-h\]

Run this script to get a list of repositories within a specific
organization.

Example:

spaid_gh_repo_list seedcase-project

Positional arguments:

1. organization: The GitHub organization name.

``` bash
spaid_gh_org_invite -h
```
Expand Down
10 changes: 10 additions & 0 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,18 @@ spaid_pr_list -h
spaid_pr_merge_rebase -h
```

```{bash}
#| output: asis
spaid_pr_merge_chores -h
```

### GitHub organization management

```{bash}
#| output: asis
spaid_gh_repo_list -h
```

```{bash}
#| output: asis
spaid_gh_org_invite -h
Expand Down
28 changes: 28 additions & 0 deletions bin/spaid_gh_repo_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/zsh

help_text="
Usage: `basename $0` [-h]

Run this script to get a list of repositories within a specific organization.

Example:

spaid_gh_repo_list seedcase-project

Positional arguments:

1. organization: The GitHub organization name.
"

if [[ "$1" == "-h" ]] ; then
echo $help_text
exit 0
fi

if [[ "$1" == "" ]] ; then
echo "Error: No organization name given. Please provide an organization name."
exit 1
fi
org="$1"

gh repo list "$org" --json name -q ".[] | .name"
22 changes: 13 additions & 9 deletions bin/spaid_pr_list
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Usage: `basename $0` [-h]
Lists all open PRs in an organization.

Examples:
$ spaid_pr_list seedcase-project

spaid_pr_list seedcase-project

Positional argument:

Expand All @@ -18,13 +19,16 @@ if [[ "$1" == "-h" ]] ; then
exit 0
fi


org="$1"
# Needs to be converted to an array with `()`.
repos=($(gh repo list "$org" --json name -q ".[] | .name"))

# The `[@]` pulls out all items in the array.
for repo in "${repos[@]}"; do
gh pr list --repo "$org/$repo" --json number,title,headRepository --template \
'{{range .}}{{ tablerow (.headRepository.name) (printf "#%v" .number | autocolor "cyan") .title }}{{end}}'
done

if [[ "$org" == "" ]] ; then
echo "Error: No organization name given. Please provide an organization name."
exit 1
fi

gh search prs \
--owner "$org" \
--state open \
--limit 100

46 changes: 46 additions & 0 deletions bin/spaid_pr_merge_chores
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/zsh

help_text="
Usage: `basename $0` [-h]

Go through all open PRs in a GitHub organization (or optionally in only one repo)
and do a merge rebase on them if they contain the string 'chore(sync):' or
'ci(pre-commit):' in the title. Requires admin privilege, so not everyone can
use this command.

Examples:

spaid_pr_merge_chores seedcase-project

Positional arguments:

- org: Required. The name of the GitHub organization.
- repo: Optional. The name of the repository in the GitHub organization.
If not given, the command will run on all repositories in the organization.
"

if [[ "$1" == "-h" ]] ; then
echo $help_text
exit 0
fi

org="$1"
repo="$2"

chores=$(gh search prs \
--archived=false \
--owner "$org" \
--repo "$repo" \
--state open \
--limit 100 \
--json title,repository,number \
--jq 'map(select(.title | contains("chore(sync):") or contains("ci(pre-commit):")))'
)

echo $chores |
jq -c '.[]' |
while read pr; do
repo=$(echo $pr | jq -r ".repository.name")
number=$(echo $pr | jq -r ".number")
spaid_pr_merge_rebase "$org" "$repo" "$number"
done
21 changes: 18 additions & 3 deletions bin/spaid_pr_merge_rebase
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
help_text="
Usage: `basename $0` [-h]

Approve a PR and do a merge rebase on multiple PRs in a single repository.
Approve and do a merge rebase on multiple PRs in a single repository.
Requires admin privilege, so not everyone can use this command.

Examples:

# Do merge rebase on (fake) PRs 1, 2, and 3.
$ spaid_pr_merge_rebase seedcase-project seedcase-theme 1 2 3
spaid_pr_merge_rebase seedcase-project seedcase-theme 1 2 3

Positional arguments:

Expand All @@ -23,6 +23,21 @@ if [[ "$1" == "-h" ]] ; then
exit 0
fi

if [[ "$1" == "" ]] ; then
echo "Error: No organization name given. Please provide an organization name."
exit 1
fi

if [[ "$2" == "" ]] ; then
echo "Error: No repository name given. Please provide a repository name."
exit 1
fi

if [[ "$3" == "" ]] ; then
echo "Error: No PR number(s) given. Please provide one or more PR numbers."
exit 1
fi

org="$1"
repo="$2"
# Shifts are needed to get all numbers at the end.
Expand All @@ -32,6 +47,6 @@ pr_numbers=("$@")

# Allow for loop access to each item in array using `[@]`.
for pr_number in "${pr_numbers[@]}"; do
gh pr approve --repo "$org/$repo" $pr_number
gh pr review --repo "$org/$repo" $pr_number --approve --body "Approved via spaid helper command."
gh pr merge --repo "$org/$repo" --admin --rebase $pr_number
done
6 changes: 5 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
just --list --unsorted

# Run all recipes.
run-all: reset-local-bin install build-readme
run-all: reset-local-bin executable install build-readme

# Set all files in `bin/` as executable
executable:
chmod +x bin/*

# Install all scripts in `bin/` to `~/.local/bin/`.
install:
Expand Down