Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start a github example for protections #73

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
69 changes: 69 additions & 0 deletions 36_git/sections/EXPLORE_GITHUB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# EXPLORING GITHUB

TODO:

* Find public repos without codeowners
* Clone add codeowners.
* add branch protection for codeowners.
* Check license as well.

Ref: [NEW_REPOS.md](./NEW_REPOS.md)

## List repos

```sh
export PAGER=

# list all repos
gh repo ls --limit 150 --json name,isPrivate,isFork | jq .

# filter non-forks and public
gh repo ls --limit 150 --json name,isPrivate,isFork | jq -r '.[] | select(.isFork == false and .isPrivate == false) | (.name)'
```

```sh
# find the default branch for this repo
gh api repos/chrisguest75/shell_examples | jq -r '.default_branch'
```

## Codeowners

```sh
# get codeowners errors
gh api repos/chrisguest75/shell_examples/codeowners/errors

# get file from repo (public only)
curl https://raw.githubusercontent.com/chrisguest75/github-of-life/main/CODEOWNERS
```

List if repo has a codeowners file or not

```sh
GITHUBUSER=chrisguest75
while IFS='' read -r reponame
do
DEFAULT_BRANCH=$(gh api repos/${GITHUBUSER}/${reponame} | jq -r '.default_branch')
CODEOWNERS="✅"
ERRORS=$(gh api repos/${GITHUBUSER}/${reponame}/codeowners/errors) 2> /dev/null
if [[ $? -ne 0 ]]; then
CODEOWNERS="❌ \033[33merrors\033[0m"
fi
echo "${reponame}/${DEFAULT_BRANCH} ${CODEOWNERS}"
done < <(gh repo ls --limit 150 --json name,isPrivate,isFork | jq -r '.[] | select(.isFork == false and .isPrivate == false) | (.name)')
```

## Branches and protections

```sh
gh api 'repos/chrisguest75/github-of-life/branches' | jq '.[] | .name'

# branch protections
gh api 'repos/chrisguest75/github-of-life/branches?protected=false'

gh pr --repo chrisguest75/shell_examples ls
```

## Resources

* https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
* https://docs.github.com/en/rest/repos/repos#get-a-repository
3 changes: 2 additions & 1 deletion 36_git/sections/NEW_REPOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Click `Add File` button in `github` portal. Type in name as `LICENSE` and choos
More info on [CODEOWNERS](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)

```txt
@chrisguest75
* @chrisguest75
.github/* @chrisguest75
```

## Adding pipelines
Expand Down