Skip to content

Instantly share code, notes, and snippets.

View joshjohanning's full-sized avatar
:octocat:
Upcoming out of office - Oct 22-31

Josh Johanning joshjohanning

:octocat:
Upcoming out of office - Oct 22-31
View GitHub Profile
@joshjohanning
joshjohanning / dependency-review.yml
Created April 25, 2023 17:46
A required workflow for using dependency-review-action
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]
permissions:
{
"SPDXID": "SPDXRef-DOCUMENT",
"spdxVersion": "SPDX-2.3",
"creationInfo": {
"created": "2023-04-24T17:02:08Z",
"creators": [
"Tool: GitHub.com-Dependency-Graph"
]
},
"name": "com.github.joshjohanning-org/ghas-demo",
@joshjohanning
joshjohanning / gitlab-export-group-members.sh
Created March 31, 2023 18:50
export group members from gitlab
#!/bin/bash
# usage:
# ./gitlab-export-users-in-group.sh 2 > users.csv
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <group_id> - obtain from the overview page of your group"
exit 1
fi
@joshjohanning
joshjohanning / gitlab-create-merge-request.sh
Created March 30, 2023 21:52
create gitlab merge requests via the api
#!/bin/bash
GITLAB_URL="https://example.gitlab.com/"
PROJECT_ID="2" # get this id via the repo/project's overview page
ACCESS_TOKEN="glpat-abc"
# Create a new merge request
curl --header "Private-Token: $ACCESS_TOKEN" \
"$GITLAB_URL/api/v4/projects/$PROJECT_ID/merge_requests" \
--data "source_branch=my-branch" \
--data "target_branch=main" \
@joshjohanning
joshjohanning / gitlab-export-merge-requests.sh
Last active March 30, 2023 18:09
export gitlab merge requests
#!/bin/bash
# credits @tspascoal
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <project_id> - obtain the numeric project ID from the project/repo's home page"
exit 1
fi
if [ -z "$GL_TOKEN" ]; then
@joshjohanning
joshjohanning / workflow.yml
Created March 30, 2023 13:57
sample workflow for github app
name: demo
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
@joshjohanning
joshjohanning / dependency-review.yml
Created February 28, 2023 18:33
A required workflow you can use for ensuring no NEW vulnerabilities are added in pull requests
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]
permissions:
@joshjohanning
joshjohanning / update-repos-in-org-from-internal-to-private.sh
Created November 12, 2022 15:53
Update the repo visibility for all repos in a github org from internal to private
ORG_NAME="joshjohanning-org"
# get a list of internal repos in my github org
repos=$(gh api "/orgs/$ORG_NAME/repos" -q '.[] | select(.visibility == "internal") | .name' --paginate)
# loop through repos
for repo in $repos; do
echo "Changing visiblity to internal: $ORG_NAME/$repo"
echo "Changing visiblity to internal: $ORG_NAME/$repo" >> change-repo-visiblity.log
gh repo edit $ORG_NAME/$repo --visibility private
@joshjohanning
joshjohanning / migrate-git-repos.md
Created October 5, 2022 16:10 — forked from dbirks/migrate-git-repos.md
Script to fully migrate git repos, including all tags and branches

Migrate git repos script

I used this for migrating git repos from Bitbucket to Github. It uses git's --mirror flag for cloning and pushing to also transfer all tags and branches.

It would be helpful to have SSH keys set up on both ends. Then all you should have to do is to make sure the hardcoded orgname is set to the appropriate one for both the source and destination.

Once I migrated repos, I used this to replace my origin url locally (assumes using ssh):

sed -i s/bitbucket.org:orgname/github.com:orgname/g .git/config
@joshjohanning
joshjohanning / package.json
Created September 23, 2022 16:05
vulnerable javascript package
"tar": "2.2.2"