Skip to content

Instantly share code, notes, and snippets.

View joshjohanning's full-sized avatar
:octocat:

Josh Johanning joshjohanning

:octocat:
View GitHub Profile
@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"
@joshjohanning
joshjohanning / github-advanced-security-resources.md
Last active September 16, 2022 17:51
GitHub Advanced Security Resources
@joshjohanning
joshjohanning / Add-Vulnerable-NuGet-Package.sh
Created August 24, 2022 16:56
Sample vulnerable NuGet package for Dependabot
dotnet add src/MyProject.csproj package Microsoft.Data.OData -v 5.0.1
@joshjohanning
joshjohanning / New.cs
Created August 24, 2022 16:31
sample vulnerable .NET C# code for CodeQL
using System;
using System.Security.Cryptography;
class WeakEncryption
{
public static byte[] encryptString()
{
SymmetricAlgorithm serviceProvider = new DESCryptoServiceProvider();
byte[] key = { 16, 22, 240, 11, 18, 150, 192, 21 };
serviceProvider.Key = key;
ICryptoTransform encryptor = serviceProvider.CreateEncryptor();