├── .gitignore ├── test.sh ├── .github ├── CODEOWNERS └── workflows │ ├── release.yaml │ └── build.yaml ├── .editorconfig ├── .goreleaser.yml ├── go.mod ├── README.md ├── go.sum ├── LICENSE └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | /gh-pma 2 | /gh-pma.exe 3 | /*.log 4 | .DS_Store 5 | thumbs.DB 6 | .env 7 | /*.csv 8 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | rm -f *.log 4 | rm -f *.csv 5 | go get; 6 | go build; 7 | 8 | ./gh-pma $@ -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # These owners will be the default owners for everything in the repo # 3 | ###################################################################### 4 | * @mona-actions/Team-ES -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{*.go,go.mod,go.sum}] 12 | indent_style = tab 13 | indent_size = 4 14 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: release 2 | on: 3 | push: 4 | tags: 5 | - "v*" 6 | permissions: 7 | contents: write 8 | 9 | jobs: 10 | release: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | 15 | - uses: cli/gh-extension-precompile@v1 16 | with: 17 | go_version: ">=1.18" 18 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - 'feature/**' 8 | - 'hotfix/**' 9 | - 'defect/**' 10 | paths-ignore: 11 | - '*.md' 12 | pull_request: 13 | branches: 14 | - main 15 | paths-ignore: 16 | - '*.md' 17 | 18 | jobs: 19 | build: 20 | runs-on: ubuntu-latest 21 | 22 | concurrency: 23 | group: build-${{ github.ref }} 24 | cancel-in-progress: true 25 | 26 | permissions: read-all 27 | 28 | env: 29 | CI: true 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: actions/setup-go@v3 35 | with: 36 | go-version: ">=1.18" 37 | 38 | - run: go get -v -t -d ./... 39 | 40 | - run: go build -v . -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | project_name: gh_clone_webhooks 2 | 3 | release: 4 | prerelease: auto 5 | 6 | before: 7 | hooks: 8 | # You may remove this if you don't use go modules. 9 | - go mod tidy 10 | # you may remove this if you don't need go generate 11 | - go generate ./... 12 | 13 | builds: 14 | - env: 15 | - CGO_ENABLED=0 16 | goos: 17 | - linux 18 | - windows 19 | - darwin 20 | 21 | archives: 22 | - replacements: 23 | darwin: macos 24 | linux: linux 25 | windows: windows 26 | 386: i386 27 | amd64: x86_64 28 | files: 29 | - license 30 | - readme.md 31 | format_overrides: 32 | - goos: windows 33 | format: zip 34 | wrap_in_directory: 'true' 35 | 36 | checksum: 37 | name_template: "checksums.txt" 38 | 39 | snapshot: 40 | name_template: "{{ incpatch .Version }}" 41 | 42 | changelog: 43 | skip: true 44 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/mona-actions/gh-pma 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/briandowns/spinner v1.23.0 7 | github.com/cli/go-gh v0.0.3 8 | github.com/fatih/color v1.15.0 9 | github.com/pterm/pterm v0.12.63 10 | github.com/shurcooL/graphql v0.0.0-20230714182844-3e04114ae69a 11 | github.com/spf13/cobra v1.5.0 12 | golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 13 | ) 14 | 15 | require ( 16 | atomicgo.dev/cursor v0.1.3 // indirect 17 | atomicgo.dev/keyboard v0.2.9 // indirect 18 | atomicgo.dev/schedule v0.0.2 // indirect 19 | github.com/cli/safeexec v1.0.0 // indirect 20 | github.com/cli/shurcooL-graphql v0.0.1 // indirect 21 | github.com/containerd/console v1.0.3 // indirect 22 | github.com/gookit/color v1.5.3 // indirect 23 | github.com/henvic/httpretty v0.0.6 // indirect 24 | github.com/inconshreveable/mousetrap v1.0.0 // indirect 25 | github.com/lithammer/fuzzysearch v1.1.8 // indirect 26 | github.com/mattn/go-colorable v0.1.13 // indirect 27 | github.com/mattn/go-isatty v0.0.17 // indirect 28 | github.com/mattn/go-runewidth v0.0.14 // indirect 29 | github.com/rivo/uniseg v0.4.4 // indirect 30 | github.com/spf13/pflag v1.0.5 // indirect 31 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 32 | golang.org/x/net v0.6.0 // indirect 33 | golang.org/x/sys v0.10.0 // indirect 34 | golang.org/x/term v0.10.0 // indirect 35 | golang.org/x/text v0.11.0 // indirect 36 | gopkg.in/yaml.v3 v3.0.1 // indirect 37 | ) 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gh-pma 2 | Post-Migration Audit (PMA) Extension For GitHub CLI. This extension is used to compare GitHub Enterprise (Server or Cloud) to GitHub Enterprise Cloud (includes Managed Users) migrations after using the [GEI](https://github.com/github/gh-gei) tool. 3 | 4 | Will report on: 5 | - Repositories from source exist in target 6 | - Repository target visibilities match source 7 | - If the following exist in source repositories: 8 | - Secrets 9 | - Variables 10 | - Environments 11 | 12 | Optionally you can choose to create a CSV in your file system (`-c` flag) and/or an issue (`-i` flag) in the target repo with the results. 13 | 14 | The tool could be expanded to include other non-migratable settings (see [what is & isn't migrated](https://docs.github.com/en/migrations/using-github-enterprise-importer/understanding-github-enterprise-importer/migration-support-for-github-enterprise-importer#githubcom-migration-support) during a migration with [GEI](https://github.com/github/gh-gei)). 15 | 16 | [![build](https://github.com/mona-actions/gh-pma/actions/workflows/build.yaml/badge.svg)](https://github.com/mona-actions/gh-pma/actions/workflows/build.yaml) 17 | [![release](https://github.com/mona-actions/gh-pma/actions/workflows/release.yaml/badge.svg)](https://github.com/mona-actions/gh-pma/actions/workflows/release.yaml) 18 | 19 | ## Planned Updates 20 | - Add detection of: 21 | - Codespaces Secrets 22 | - Dependabot Secrets 23 | - Environment Secrets & Vars (currently just Environments are detected) 24 | - GitHub App for authentication 25 | 26 | ## Caveat On LFS Detection 27 | This currently only checks the default branch for a `.gitattributes` file and validates a line exists with `filter=LFS`. This doesn't mean your repository actually contains LFS objects, it's just a litmus test to detect the possibility. Without the `.gitattributes` file, no LFS files would exist, except in the case that a branch (not the default) is using LFS and has diverged from default in that way. 28 | 29 | ## Prerequisites 30 | - [GitHub CLI](https://cli.github.com/manual/installation) installed. 31 | 32 | ## Permissions Required 33 | You will only be able to see repos your account has access too, so make sure your PATs for the source and destination are correct. Just like [GEI](https://github.com/github/gh-gei), the tool uses `GH_PAT` and `GH_SOURCE_PAT` environment variables to communicate with source and target, unless you manually override with the provided flags. 34 | 35 | Those PATs should adhere to the same scopes as [GEI](https://github.com/github/gh-gei) (see [documentation](https://docs.github.com/en/migrations/using-github-enterprise-importer/preparing-to-migrate-with-github-enterprise-importer/managing-access-for-github-enterprise-importer#required-scopes-for-personal-access-tokens)). 36 | 37 | ## Install 38 | 39 | ```bash 40 | $ gh extension install mona-actions/gh-pma 41 | ``` 42 | 43 | ## Upgrade 44 | ```bash 45 | $ gh extension upgrade pma 46 | ``` 47 | 48 | ## Usage 49 | 50 | ```txt 51 | $ gh pma [flags] 52 | ``` 53 | 54 | ```txt 55 | Post-Migration Audit (PMA) Extension For GitHub CLI. Used to compare GitHub Enterprise (Server or Cloud) to GitHub Enterprise Cloud (includes Managed Users) migrations. 56 | 57 | Usage: 58 | gh pma [flags] 59 | 60 | Flags: 61 | --confirm Auto respond to visibility alignment confirmation prompt 62 | -c, --create-csv Whether to create a CSV file with the results. 63 | -i, --create-issues Whether to create issues in target org repositories or not. 64 | --ghes-api-url string Required if migration source is GHES. The domain name for your GHES instance. For example: ghes.contoso.com (default "github.com") 65 | --github-source-org string Uses GH_SOURCE_PAT env variable or --github-source-pat option. Will fall back to GH_PAT or --github-target-pat if not set. 66 | --github-source-pat string 67 | --github-target-org string Uses GH_PAT env variable or --github-target-pat option. 68 | --github-target-pat string 69 | -h, --help help for gh 70 | --threads int Number of threads to process concurrently. Maximum of 10 allowed. Increasing this number could get your PAT blocked due to API limiting. (default 3) 71 | -v, --version version for gh 72 | ``` -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | atomicgo.dev/cursor v0.1.3 h1:w8GcylMdZRyFzvDiGm3wy3fhZYYT7BwaqNjUFHxo0NU= 2 | atomicgo.dev/cursor v0.1.3/go.mod h1:Lr4ZJB3U7DfPPOkbH7/6TOtJ4vFGHlgj1nc+n900IpU= 3 | atomicgo.dev/keyboard v0.2.9 h1:tOsIid3nlPLZ3lwgG8KZMp/SFmr7P0ssEN5JUsm78K8= 4 | atomicgo.dev/keyboard v0.2.9/go.mod h1:BC4w9g00XkxH/f1HXhW2sXmJFOCWbKn9xrOunSFtExQ= 5 | atomicgo.dev/schedule v0.0.2 h1:2e/4KY6t3wokja01Cyty6qgkQM8MotJzjtqCH70oX2Q= 6 | atomicgo.dev/schedule v0.0.2/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU= 7 | github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= 8 | github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= 9 | github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8= 10 | github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII= 11 | github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k= 12 | github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI= 13 | github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c= 14 | github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE= 15 | github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= 16 | github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A= 17 | github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE= 18 | github.com/cli/go-gh v0.0.3 h1:GcVgUa7q0SeauIRbch3VSUXVij6+c49jtAHv7WuWj5c= 19 | github.com/cli/go-gh v0.0.3/go.mod h1:J1eNgrPJYAUy7TwPKj7GW1ibqI+WCiMndtyzrCyZIiQ= 20 | github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI= 21 | github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q= 22 | github.com/cli/shurcooL-graphql v0.0.1 h1:/9J3t9O6p1B8zdBBtQighq5g7DQRItBwuwGh3SocsKM= 23 | github.com/cli/shurcooL-graphql v0.0.1/go.mod h1:U7gCSuMZP/Qy7kbqkk5PrqXEeDgtfG5K+W+u8weorps= 24 | github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= 25 | github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= 26 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 27 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 28 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 29 | github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= 30 | github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= 31 | github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= 32 | github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= 33 | github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE= 34 | github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE= 35 | github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTxs= 36 | github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo= 37 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= 38 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 39 | github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 40 | github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= 41 | github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= 42 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 43 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 44 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 45 | github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= 46 | github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= 47 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 48 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 49 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 50 | github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= 51 | github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 52 | github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 53 | github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= 54 | github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 55 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 56 | github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= 57 | github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg= 58 | github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE= 59 | github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU= 60 | github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= 61 | github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= 62 | github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= 63 | github.com/pterm/pterm v0.12.63 h1:fHlrpFiI9qLtEU0TWDWMU+tAt4qKJ/s157BEAPtGm8w= 64 | github.com/pterm/pterm v0.12.63/go.mod h1:Bq1eoUJ6BhUzzXG8WxA4l7T3s7d3Ogwg7v9VXlsVat0= 65 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 66 | github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= 67 | github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 68 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 69 | github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= 70 | github.com/shurcooL/graphql v0.0.0-20230714182844-3e04114ae69a h1:rknsHBkRVUMU8d3Y9Gjumk2Qr5+RKPiBBJukqJaqgXc= 71 | github.com/shurcooL/graphql v0.0.0-20230714182844-3e04114ae69a/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE= 72 | github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= 73 | github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= 74 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 75 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 76 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 77 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 78 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 79 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 80 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= 81 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= 82 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= 83 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 84 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 85 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 86 | golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= 87 | golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= 88 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 89 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 90 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 91 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 92 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= 93 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 94 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 95 | golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= 96 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 97 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 98 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 99 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 100 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 101 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 102 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 103 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 104 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 105 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 106 | golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 107 | golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 108 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 109 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 110 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 111 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 112 | golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= 113 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 114 | golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= 115 | golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 116 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 117 | golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 118 | golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 119 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 120 | golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= 121 | golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 122 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 123 | golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= 124 | golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= 125 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 126 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 127 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 128 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 129 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 130 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 131 | golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= 132 | golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 133 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 134 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 135 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 136 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 137 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 138 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 139 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 140 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 141 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 142 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 143 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 144 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 145 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= 146 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 147 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 148 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 149 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "encoding/base64" 7 | "encoding/json" 8 | "errors" 9 | "fmt" 10 | "net/url" 11 | "os" 12 | "regexp" 13 | "strconv" 14 | "strings" 15 | "sync" 16 | "time" 17 | "unicode" 18 | 19 | "github.com/briandowns/spinner" 20 | "github.com/cli/go-gh" 21 | "github.com/cli/go-gh/pkg/api" 22 | "github.com/fatih/color" 23 | "github.com/pterm/pterm" 24 | "github.com/shurcooL/graphql" 25 | "github.com/spf13/cobra" 26 | "golang.org/x/exp/slices" 27 | ) 28 | 29 | var ( 30 | // flag vars 31 | AutoConfirm = false 32 | CreateIssues = false 33 | CreateCSV = false 34 | GithubSourceOrg string 35 | GithubTargetOrg string 36 | ApiUrl string 37 | GithubSourcePat string 38 | GithubTargetPat string 39 | DefaultBranchRef = fmt.Sprint( 40 | "Post-Migration Audit (PMA) Extension For GitHub CLI. Used to compare ", 41 | "GitHub Enterprise (Server or Cloud) to GitHub Enterprise Cloud (includes ", 42 | "Managed Users) migrations.", 43 | ) 44 | 45 | // tool vars 46 | 47 | AnsiRegex string 48 | DefaultApiUrl string = "github.com" 49 | DefaultIssueTitleTemplate string = "Post Migration Audit" 50 | SourceRestClient api.RESTClient 51 | TargetRestClient api.RESTClient 52 | SourceGraphqlClient api.GQLClient 53 | TargetGraphqlClient api.GQLClient 54 | SourceRepositories []repository = []repository{} 55 | TargetRepositories []repository = []repository{} 56 | ToProcessRepositories []repository = []repository{} 57 | LogFile *os.File 58 | Threads int 59 | ResultsTable pterm.TableData 60 | WaitGroup sync.WaitGroup 61 | 62 | // Create some colors and a spinner 63 | Red = color.New(color.FgRed).SprintFunc() 64 | Yellow = color.New(color.FgYellow).SprintFunc() 65 | Cyan = color.New(color.FgCyan).SprintFunc() 66 | Pink = color.New(color.FgHiMagenta).SprintFunc() 67 | Spinner = spinner.New(spinner.CharSets[2], 100*time.Millisecond) 68 | 69 | // Create the root cobra command 70 | rootCmd = &cobra.Command{ 71 | Use: "gh pma", 72 | Short: DefaultBranchRef, 73 | Long: DefaultBranchRef, 74 | Version: "1.0.0", 75 | SilenceUsage: true, 76 | SilenceErrors: true, 77 | RunE: Process, 78 | } 79 | ) 80 | 81 | type repositoryQuery struct { 82 | Organization struct { 83 | Repos repoPage `graphql:"repositories(first: 100, after: $page)"` 84 | } `graphql:"organization(login: $owner)"` 85 | } 86 | type rateResponse struct { 87 | Limit int 88 | Remaining int 89 | Reset int 90 | Used int 91 | } 92 | type apiResponse struct { 93 | Resources struct { 94 | Core rateResponse 95 | Graphql rateResponse 96 | } 97 | Message string 98 | Rate rateResponse 99 | } 100 | type file struct { 101 | Content string 102 | } 103 | type environments struct { 104 | Environments []environment 105 | Total_Count int 106 | } 107 | type environment struct { 108 | Name string 109 | } 110 | type issues struct { 111 | Items []issue 112 | Total_Count int 113 | } 114 | type issue struct { 115 | Title string 116 | ID int 117 | Number int 118 | State string 119 | } 120 | type repoPage struct { 121 | PageInfo struct { 122 | HasNextPage bool 123 | EndCursor graphql.String 124 | } 125 | Nodes []repoNode 126 | } 127 | 128 | type branchRef struct { 129 | Name string 130 | } 131 | type repoNode struct { 132 | Name string 133 | NameWithOwner string 134 | Visibility string 135 | Owner owner 136 | DefaultBranchRef branchRef 137 | } 138 | type repository struct { 139 | Name string 140 | Owner string 141 | NameWithOwner string 142 | DefaultBranchRef branchRef 143 | Visibility string 144 | TargetVisibility string 145 | ExistsInTarget bool 146 | Secrets secrets 147 | Variables variables 148 | Environments environments 149 | LFS file 150 | } 151 | type owner struct { 152 | Login string 153 | } 154 | type secrets struct { 155 | Secrets []secret 156 | Total_Count int 157 | } 158 | type secret struct { 159 | Name string 160 | } 161 | type variables struct { 162 | Variables []variable 163 | Total_Count int 164 | } 165 | type variable struct { 166 | Name string 167 | Value string 168 | } 169 | type user struct { 170 | Login string 171 | } 172 | 173 | func init() { 174 | 175 | rootCmd.PersistentFlags().StringVar( 176 | &GithubSourceOrg, 177 | "github-source-org", 178 | "", 179 | fmt.Sprint( 180 | "Uses GH_SOURCE_PAT env variable or --github-source-pat option. Will ", 181 | "fall back to GH_PAT or --github-target-pat if not set.", 182 | ), 183 | ) 184 | rootCmd.PersistentFlags().StringVar( 185 | &GithubTargetOrg, 186 | "github-target-org", 187 | "", 188 | "Uses GH_PAT env variable or --github-target-pat option.", 189 | ) 190 | rootCmd.PersistentFlags().StringVar( 191 | &ApiUrl, 192 | "ghes-api-url", 193 | DefaultApiUrl, 194 | fmt.Sprint( 195 | "Required if migration source is GHES. The domain name for your GHES ", 196 | "instance. For example: ghes.contoso.com", 197 | ), 198 | ) 199 | rootCmd.PersistentFlags().StringVar( 200 | &GithubSourcePat, 201 | "github-source-pat", 202 | "", 203 | "", 204 | ) 205 | rootCmd.PersistentFlags().StringVar( 206 | &GithubTargetPat, 207 | "github-target-pat", 208 | "", 209 | "", 210 | ) 211 | rootCmd.PersistentFlags().IntVar( 212 | &Threads, 213 | "threads", 214 | 3, 215 | fmt.Sprint( 216 | "Number of threads to process concurrently. Maximum of 10 allowed. ", 217 | "Increasing this number could get your PAT blocked due to API limiting.", 218 | ), 219 | ) 220 | rootCmd.PersistentFlags().BoolVar( 221 | &AutoConfirm, 222 | "confirm", 223 | false, 224 | "Auto respond to visibility alignment confirmation prompt", 225 | ) 226 | rootCmd.PersistentFlags().BoolVarP( 227 | &CreateIssues, 228 | "create-issues", 229 | "i", 230 | false, 231 | "Whether to create issues in target org repositories or not.", 232 | ) 233 | rootCmd.PersistentFlags().BoolVarP( 234 | &CreateCSV, 235 | "create-csv", 236 | "c", 237 | false, 238 | "Whether to create a CSV file with the results.", 239 | ) 240 | 241 | // make certain flags required 242 | rootCmd.MarkPersistentFlagRequired("github-source-org") 243 | rootCmd.MarkPersistentFlagRequired("github-target-org") 244 | 245 | // update version template to show extension name 246 | rootCmd.SetVersionTemplate( 247 | fmt.Sprintf("PMA Extension for GitHub CLI, v%s\n", rootCmd.Version), 248 | ) 249 | 250 | // add args here 251 | rootCmd.Args = cobra.MaximumNArgs(0) 252 | 253 | // set ANSI regex 254 | AnsiRegex = "[\u001B\u009B]" 255 | AnsiRegex += "[[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]" 256 | AnsiRegex += "*(?:;[a-zA-Z\\d]*)*)?\u0007)" 257 | AnsiRegex += "|(?:(?:\\d{1,4}(?:;\\d{0,4})*)" 258 | AnsiRegex += "?[\\dA-PRZcf-ntqry=><~]))" 259 | } 260 | 261 | func main() { 262 | if err := rootCmd.Execute(); err != nil { 263 | ExitOnError(err) 264 | } 265 | } 266 | 267 | func ExitOnError(err error) { 268 | if err != nil { 269 | rootCmd.PrintErrln(err.Error()) 270 | os.Exit(1) 271 | } 272 | } 273 | 274 | func ExitManual(err error) { 275 | Spinner.Stop() 276 | fmt.Println(err.Error()) 277 | os.Exit(1) 278 | } 279 | 280 | func OutputFlags(key string, value string) { 281 | sep := ": " 282 | fmt.Println(fmt.Sprint(Pink(key), sep, value)) 283 | Log(fmt.Sprint(key, sep, value)) 284 | } 285 | 286 | func OutputNotice(message string) { 287 | Output(message, "default", false, false) 288 | } 289 | 290 | func OutputWarning(message string) { 291 | Output(fmt.Sprint("[WARNING] ", message), "yellow", false, false) 292 | } 293 | 294 | func OutputError(message string, exit bool) { 295 | Spinner.Stop() 296 | Output(message, "red", true, exit) 297 | } 298 | 299 | func Output(message string, color string, isErr bool, exit bool) { 300 | 301 | if isErr { 302 | message = fmt.Sprint("[ERROR] ", message) 303 | } 304 | Log(StripAnsi(message)) 305 | 306 | switch { 307 | case color == "red": 308 | message = Red(message) 309 | case color == "yellow": 310 | message = Yellow(message) 311 | } 312 | fmt.Println(message) 313 | if exit { 314 | fmt.Println("") 315 | os.Exit(1) 316 | } 317 | } 318 | 319 | func AskForConfirmation(s string) (res bool, err error) { 320 | // read the input 321 | reader := bufio.NewReader(os.Stdin) 322 | // loop until a response is valid 323 | for { 324 | fmt.Printf("%s [y/n]: ", s) 325 | response, err := reader.ReadString('\n') 326 | Debug(fmt.Sprint("User responded with: ", response)) 327 | if err != nil { 328 | return false, err 329 | } 330 | response = strings.ToLower(strings.TrimSpace(response)) 331 | if response == "y" || response == "yes" { 332 | return true, err 333 | } else if response == "n" || response == "no" { 334 | return false, err 335 | } 336 | } 337 | } 338 | 339 | func DebugAndStatus(message string) string { 340 | Spinner.Suffix = fmt.Sprint( 341 | " ", 342 | message, 343 | ) 344 | return Debug(message) 345 | } 346 | 347 | func Debug(message string) string { 348 | Log(message) 349 | return message 350 | } 351 | 352 | func DisplayRateLeft() { 353 | // validate we have API attempts left 354 | rateLeft, _ := ValidateApiRate(SourceRestClient, "core") 355 | rateMessage := Cyan("API Rate Limit Left:") 356 | OutputNotice(fmt.Sprintf("%s %d", rateMessage, rateLeft)) 357 | LF() 358 | } 359 | 360 | func IsTargetProvided() bool { 361 | if GithubTargetOrg != "" { 362 | return true 363 | } 364 | return false 365 | } 366 | 367 | func GetOpts(hostname, token string) (options api.ClientOptions) { 368 | // set options 369 | opts := api.ClientOptions{ 370 | Host: hostname, 371 | CacheTTL: time.Hour, 372 | } 373 | if token != "" { 374 | opts.AuthToken = token 375 | } 376 | return opts 377 | } 378 | 379 | func LF() { 380 | fmt.Println("") 381 | } 382 | 383 | func LFSExists(base64File string) (string, bool, error) { 384 | decodedContents, err := base64.StdEncoding.DecodeString(base64File) 385 | if err != nil { 386 | return "", false, err 387 | } 388 | if strings.Contains(string(decodedContents), "filter=lfs") { 389 | return string(decodedContents), true, err 390 | } 391 | return string(decodedContents), false, err 392 | } 393 | 394 | func Log(message string) { 395 | if message != "" { 396 | message = fmt.Sprint( 397 | "[", 398 | time.Now().Format("2006-01-02 15:04:05"), 399 | "] ", 400 | message, 401 | ) 402 | } 403 | _, err := LogFile.WriteString( 404 | fmt.Sprintln(message), 405 | ) 406 | if err != nil { 407 | fmt.Println(Red("Unable to write to log file.")) 408 | fmt.Println(Red(err)) 409 | os.Exit(1) 410 | } 411 | } 412 | 413 | func Truncate(str string, limit int) string { 414 | lastSpaceIx := -1 415 | len := 0 416 | for i, r := range str { 417 | if unicode.IsSpace(r) { 418 | lastSpaceIx = i 419 | } 420 | len++ 421 | if len >= limit { 422 | if lastSpaceIx != -1 { 423 | return fmt.Sprint(str[:lastSpaceIx], "...") 424 | } else { 425 | return fmt.Sprint(str[:limit], "...") 426 | } 427 | } 428 | } 429 | return str 430 | } 431 | 432 | func StripAnsi(str string) string { 433 | regex := regexp.MustCompile(AnsiRegex) 434 | return regex.ReplaceAllString(str, "") 435 | } 436 | 437 | func SleepIfLongerThan(thisTime time.Time) { 438 | // delay if write was fast 439 | elapsed := time.Since(thisTime) 440 | if elapsed.Seconds() < 1 { 441 | wait := 1000 - elapsed.Milliseconds() 442 | DebugAndStatus( 443 | fmt.Sprintf( 444 | "Execution time was %v. Waiting for %vms to avoid rate limiting.", 445 | elapsed.Seconds(), 446 | wait, 447 | ), 448 | ) 449 | time.Sleep(time.Duration(wait) * time.Millisecond) 450 | } 451 | } 452 | 453 | func Process(cmd *cobra.Command, args []string) (err error) { 454 | 455 | // Create log file 456 | LogFile, err = os.Create( 457 | fmt.Sprint( 458 | time.Now().Format("20060102150401"), 459 | ".pma.log", 460 | ), 461 | ) 462 | if err != nil { 463 | return err 464 | } 465 | defer LogFile.Close() 466 | 467 | Debug("---- VALIDATING FLAGS & ENV VARS ----") 468 | 469 | if GithubSourcePat == "" { 470 | GithubSourcePatEnv, isSet := os.LookupEnv("GH_SOURCE_PAT") 471 | if isSet { 472 | GithubSourcePat = GithubSourcePatEnv 473 | Debug("Source PAT set from Environment Variable GH_SOURCE_PAT") 474 | } else { 475 | OutputError( 476 | fmt.Sprint( 477 | "A source PAT was not provided via --github-source-pat or ", 478 | "environment variable GH_SOURCE_PAT", 479 | ), 480 | true, 481 | ) 482 | } 483 | } 484 | 485 | if GithubTargetPat == "" { 486 | GithubTargetPatEnv, isSet := os.LookupEnv("GH_PAT") 487 | if isSet { 488 | GithubTargetPat = GithubTargetPatEnv 489 | Debug("Target PAT set from Environment Variable GH_PAT") 490 | } else { 491 | OutputError( 492 | fmt.Sprint( 493 | "A target PAT was not provided via --github-target-pat or ", 494 | "environment variable GH_PAT", 495 | ), 496 | true, 497 | ) 498 | } 499 | } 500 | 501 | // validate API URL 502 | r, _ := regexp.Compile("^http(s|):(//|)") 503 | if r.MatchString(ApiUrl) { 504 | OutputError( 505 | "--ghes-api-url should NOT contain http(s).", 506 | true, 507 | ) 508 | } 509 | 510 | if Threads > 10 { 511 | OutputError("Number of concurrent threads cannot be higher than 10.", true) 512 | } else if Threads > 3 { 513 | OutputWarning( 514 | fmt.Sprint( 515 | "Number of concurrent threads is higher than 3. This could result in ", 516 | "extreme load on your server.", 517 | ), 518 | ) 519 | } 520 | LF() 521 | 522 | // output flags for reference 523 | OutputFlags("GitHub Source Org", GithubSourceOrg) 524 | if ApiUrl != DefaultApiUrl { 525 | OutputFlags("GHES Source URL", ApiUrl) 526 | } 527 | if IsTargetProvided() { 528 | OutputFlags("GitHub Target Org", GithubTargetOrg) 529 | } 530 | OutputFlags("Read Threads", fmt.Sprintf("%d", Threads)) 531 | LF() 532 | Debug("---- SETTING UP API CLIENTS ----") 533 | 534 | // set up clients 535 | opts := GetOpts(ApiUrl, GithubSourcePat) 536 | SourceRestClient, err = gh.RESTClient(&opts) 537 | if err != nil { 538 | Debug(fmt.Sprint("Error object: ", err)) 539 | OutputError("Failed to set up source REST client.", true) 540 | } 541 | 542 | SourceGraphqlClient, err = gh.GQLClient(&opts) 543 | if err != nil { 544 | Debug(fmt.Sprint("Error object: ", err)) 545 | OutputError("Failed set set up source GraphQL client.", true) 546 | } 547 | 548 | opts = GetOpts(DefaultApiUrl, GithubTargetPat) 549 | TargetRestClient, err = gh.RESTClient(&opts) 550 | if err != nil { 551 | Debug(fmt.Sprint("Error object: ", err)) 552 | OutputError("Failed to set up target REST client.", true) 553 | } 554 | 555 | TargetGraphqlClient, err = gh.GQLClient(&opts) 556 | if err != nil { 557 | Debug(fmt.Sprint("Error object: ", err)) 558 | OutputError("Failed set set up target GraphQL client.", true) 559 | } 560 | 561 | Debug("---- LOOKING UP REPOSITORIES IN ORGS ----") 562 | 563 | Spinner.Start() 564 | 565 | // thread getting repos 566 | WaitGroup.Add(2) 567 | go GetSourceRepositories() 568 | if err != nil { 569 | Debug(fmt.Sprint("Error object: ", err)) 570 | OutputError("Failed to get source repositories.", true) 571 | } 572 | go GetTargetRepositories() 573 | if err != nil { 574 | Debug(fmt.Sprint("Error object: ", err)) 575 | OutputError("Failed to get target repositories.", true) 576 | } 577 | WaitGroup.Wait() 578 | 579 | Debug(fmt.Sprintf("Found %d repositories", len(SourceRepositories))) 580 | Debug("---- GETTING REPOSITORY DATA ----") 581 | 582 | // set up table header for displaying of data 583 | Debug("Creating table data for display...") 584 | ResultsTable = pterm.TableData{ 585 | { 586 | "Repository", 587 | "Exists In Target", 588 | "Default Branch", 589 | "Visibility", 590 | "Secrets", 591 | "Variables", 592 | "Environments", 593 | }, 594 | } 595 | 596 | // set a temp var that we can batch through without effecting the original 597 | repositoriesToProcess := SourceRepositories 598 | batchThreads := Threads 599 | batchNum := 1 600 | 601 | for len(repositoriesToProcess) > 0 { 602 | 603 | repositoriesLeft := len(repositoriesToProcess) 604 | if repositoriesLeft < Threads { 605 | batchThreads = repositoriesLeft 606 | Debug( 607 | fmt.Sprint( 608 | "Setting number of threads to", 609 | fmt.Sprintf( 610 | " %d because there are only %d repositories left.", 611 | repositoriesLeft, 612 | repositoriesLeft, 613 | ), 614 | ), 615 | ) 616 | } 617 | 618 | DebugAndStatus( 619 | fmt.Sprintf( 620 | "Running repository analysis batch #%d (%d threads)...", 621 | batchNum, 622 | batchThreads, 623 | ), 624 | ) 625 | 626 | // get the next batch into new array and remove from processing array 627 | batch := repositoriesToProcess[:batchThreads] 628 | repositoriesToProcess = repositoriesToProcess[len(batch):] 629 | 630 | // add the number of wait groups needed 631 | WaitGroup.Add(len(batch)) 632 | 633 | // process threads 634 | for i := 0; i < len(batch); i++ { 635 | Debug( 636 | fmt.Sprintf( 637 | "Running thread %d of %d on repository '%s'", 638 | i+1, 639 | len(batch), 640 | batch[i].NameWithOwner, 641 | ), 642 | ) 643 | go GetRepositoryStatistics(SourceRestClient, batch[i]) 644 | } 645 | 646 | // wait for threads to finish 647 | WaitGroup.Wait() 648 | batchNum++ 649 | } 650 | 651 | Spinner.Stop() 652 | 653 | // output table 654 | if len(SourceRepositories) > 0 { 655 | pterm.DefaultTable.WithHasHeader(). 656 | WithHeaderRowSeparator("-"). 657 | WithData(ResultsTable).Render() 658 | } else { 659 | OutputNotice("No repositories found.") 660 | return err 661 | } 662 | 663 | // Create output file 664 | if CreateCSV { 665 | outputFile, err := os.Create( 666 | fmt.Sprint( 667 | time.Now().Format("20060102150401"), 668 | ".", 669 | GithubSourceOrg, 670 | ".csv", 671 | ), 672 | ) 673 | if err != nil { 674 | return err 675 | } 676 | defer outputFile.Close() 677 | 678 | // write header 679 | _, err = outputFile.WriteString( 680 | fmt.Sprintln( 681 | "repository,", 682 | "exists_in_target,", 683 | "default_branch,", 684 | "visibility,", 685 | "secrets,", 686 | "variables,", 687 | "environments", 688 | "lfs", 689 | ), 690 | ) 691 | if err != nil { 692 | OutputError("Error writing to output file.", true) 693 | } 694 | // write body 695 | for _, repository := range SourceRepositories { 696 | line := fmt.Sprintf("%s", repository.NameWithOwner) 697 | if !IsTargetProvided() { 698 | line = fmt.Sprintf("%s,%s", line, "Unknown") 699 | } else { 700 | line = fmt.Sprintf("%s,%t", line, repository.ExistsInTarget) 701 | } 702 | _, foundLFS, _ := LFSExists(repository.LFS.Content) 703 | lfsString := "No" 704 | if foundLFS { 705 | lfsString = "Potentially" 706 | } 707 | line = fmt.Sprintf( 708 | "%s,%s,%s|%s,%d,%d,%d,%s\n", 709 | line, 710 | repository.DefaultBranchRef.Name, 711 | repository.Visibility, 712 | repository.TargetVisibility, 713 | repository.Secrets.Total_Count, 714 | repository.Variables.Total_Count, 715 | repository.Environments.Total_Count, 716 | lfsString, 717 | ) 718 | _, err = outputFile.WriteString(line) 719 | if err != nil { 720 | OutputError("Error writing to output file.", true) 721 | } 722 | } 723 | } 724 | 725 | // create issues if we need to 726 | if CreateIssues { 727 | Spinner.Start() 728 | DebugAndStatus("Attempting to create issues for repositories...") 729 | err = ProcessIssues(SourceRestClient, GithubTargetOrg, SourceRepositories) 730 | Spinner.Stop() 731 | if err != nil { 732 | return err 733 | } 734 | } 735 | 736 | // prompt for fixing 737 | if len(ToProcessRepositories) > 0 { 738 | 739 | // find out if we need to process visibility 740 | repoWord := "repository" 741 | if len(ToProcessRepositories) > 1 { 742 | repoWord = "repositories" 743 | } 744 | proceedMessage := Debug(fmt.Sprintf( 745 | "Do you want to align visibility for %d %s?", 746 | len(ToProcessRepositories), 747 | repoWord, 748 | )) 749 | 750 | // auto confirm 751 | c := true 752 | if !AutoConfirm { 753 | c, err = AskForConfirmation(Yellow(proceedMessage)) 754 | } 755 | if err != nil { 756 | OutputError(err.Error(), true) 757 | } else if !c { 758 | // warn when manually abandoned 759 | LF() 760 | OutputWarning("Alignment process abandoned.") 761 | LF() 762 | DisplayRateLeft() 763 | return err 764 | } 765 | 766 | // process if code gets to here 767 | Spinner.Start() 768 | err = ProcessRepositoryVisibilities( 769 | TargetRestClient, 770 | GithubTargetOrg, 771 | ToProcessRepositories, 772 | ) 773 | Spinner.Stop() 774 | 775 | // on successful processing 776 | if err == nil { 777 | LF() 778 | OutputNotice( 779 | fmt.Sprintf( 780 | "Successfully processed %d repositories.", 781 | len(ToProcessRepositories), 782 | ), 783 | ) 784 | LF() 785 | } 786 | } 787 | 788 | DisplayRateLeft() 789 | 790 | // always return 791 | return err 792 | } 793 | 794 | func ValidateApiRate( 795 | client api.RESTClient, 796 | requestType string, 797 | ) (left int, err error) { 798 | 799 | apiResponse := apiResponse{} 800 | attempts := 0 801 | rateRemaining := 0 802 | 803 | for { 804 | 805 | // after 240 attempts (1 hour), end the scrip. 806 | if attempts >= 240 { 807 | return 0, errors.New( 808 | fmt.Sprint( 809 | "After an hour of retrying, the API rate limit has not ", 810 | "refreshed. Aborting.", 811 | ), 812 | ) 813 | } 814 | 815 | // get the current rate liit left or error out if request fails 816 | err = client.Get("rate_limit", &apiResponse) 817 | if err != nil { 818 | Debug("Failed to get rate limit from GitHub server.") 819 | return 0, err 820 | } 821 | 822 | // if rate limiting is disabled, do not proceed 823 | if apiResponse.Message == "Rate limiting is not enabled." { 824 | Debug("Rate limit is not enabled.") 825 | return 0, err 826 | } 827 | // choose which response to validate 828 | switch { 829 | default: 830 | return 0, errors.New( 831 | fmt.Sprintf( 832 | "Invalid API request type provided: '%s'", 833 | requestType, 834 | ), 835 | ) 836 | case requestType == "core": 837 | rateRemaining = apiResponse.Resources.Core.Remaining 838 | case requestType == "graphql": 839 | rateRemaining = apiResponse.Resources.Graphql.Remaining 840 | } 841 | // validate there is rate left 842 | if rateRemaining <= 0 { 843 | attempts++ 844 | DebugAndStatus( 845 | fmt.Sprint( 846 | "API rate limit ", 847 | fmt.Sprintf( 848 | "(%s) has none remaining. Sleeping for 15 seconds (attempt #%d)", 849 | requestType, 850 | attempts, 851 | ), 852 | ), 853 | ) 854 | time.Sleep(15 * time.Second) 855 | } else { 856 | break 857 | } 858 | } 859 | return rateRemaining, err 860 | } 861 | 862 | func GetRepositoryStatistics(client api.RESTClient, repoToProcess repository) { 863 | 864 | // validate we have API attempts left 865 | _, timeoutErr := ValidateApiRate(client, "core") 866 | if timeoutErr != nil { 867 | OutputError(timeoutErr.Error(), true) 868 | } 869 | 870 | // start timer 871 | start := time.Now() 872 | 873 | // get number of secrets 874 | var secretsResponse secrets 875 | secretsErr := client.Get( 876 | fmt.Sprintf( 877 | "repos/%s/actions/secrets", 878 | repoToProcess.NameWithOwner, 879 | ), 880 | &secretsResponse, 881 | ) 882 | Debug(fmt.Sprintf( 883 | "Secrets from %s: %+v", 884 | repoToProcess.NameWithOwner, 885 | secretsResponse, 886 | )) 887 | if secretsErr != nil { 888 | ExitManual(secretsErr) 889 | } else { 890 | repoToProcess.Secrets = secretsResponse 891 | } 892 | 893 | // validate we have API attempts left 894 | 895 | _, timeoutErr = ValidateApiRate(client, "core") 896 | if timeoutErr != nil { 897 | OutputError(timeoutErr.Error(), true) 898 | } 899 | 900 | // get number of variables 901 | var variablesResponse variables 902 | variablesErr := client.Get( 903 | fmt.Sprintf( 904 | "repos/%s/actions/variables", 905 | repoToProcess.NameWithOwner, 906 | ), 907 | &variablesResponse, 908 | ) 909 | Debug(fmt.Sprintf( 910 | "Variables from %s: %+v", 911 | repoToProcess.NameWithOwner, 912 | variablesResponse, 913 | )) 914 | if variablesErr != nil { 915 | ExitManual(variablesErr) 916 | } else { 917 | repoToProcess.Variables = variablesResponse 918 | } 919 | 920 | // validate we have API attempts left 921 | _, timeoutErr = ValidateApiRate(client, "core") 922 | if timeoutErr != nil { 923 | OutputError(timeoutErr.Error(), true) 924 | } 925 | 926 | // get number of variables 927 | var envResponse environments 928 | envsErr := client.Get( 929 | fmt.Sprintf( 930 | "repos/%s/environments", 931 | repoToProcess.NameWithOwner, 932 | ), 933 | &envResponse, 934 | ) 935 | Debug(fmt.Sprintf( 936 | "Environments from %s: %+v", 937 | repoToProcess.NameWithOwner, 938 | envResponse, 939 | )) 940 | if envsErr != nil { 941 | ExitManual(envsErr) 942 | } else { 943 | repoToProcess.Environments = envResponse 944 | } 945 | 946 | // get LFS definition file 947 | var fileResponse file 948 | _ = client.Get( 949 | fmt.Sprintf( 950 | "repos/%s/contents/.gitattributes", 951 | repoToProcess.NameWithOwner, 952 | ), 953 | &fileResponse, 954 | ) 955 | Debug(fmt.Sprintf( 956 | "Contents of .gitattributes from %s: %+v", 957 | repoToProcess.NameWithOwner, 958 | fileResponse, 959 | )) 960 | repoToProcess.LFS = fileResponse 961 | 962 | // find if repo exists in target 963 | tIdx := slices.IndexFunc(TargetRepositories, func(r repository) bool { 964 | return r.Name == repoToProcess.Name 965 | }) 966 | if tIdx < 0 { 967 | repoToProcess.ExistsInTarget = false 968 | repoToProcess.TargetVisibility = fmt.Sprintf("UNKNOWN") 969 | } else { 970 | repoToProcess.ExistsInTarget = true 971 | repoToProcess.TargetVisibility = TargetRepositories[tIdx].Visibility 972 | 973 | // add this repo to array of processing if visibilties don't match 974 | if repoToProcess.Visibility != TargetRepositories[tIdx].Visibility { 975 | ToProcessRepositories = append(ToProcessRepositories, repoToProcess) 976 | } 977 | } 978 | 979 | // find index of repo in original list and overwite it 980 | idx := slices.IndexFunc(SourceRepositories, func(r repository) bool { 981 | return r.NameWithOwner == repoToProcess.NameWithOwner 982 | }) 983 | if idx < 0 { 984 | OutputError( 985 | fmt.Sprintf( 986 | "Error finding batch repository in original list: %s", 987 | repoToProcess.NameWithOwner, 988 | ), 989 | false, 990 | ) 991 | } else { 992 | SourceRepositories[idx] = repoToProcess 993 | } 994 | 995 | // write to table for output 996 | visiblity := fmt.Sprintf( 997 | "%s", 998 | repoToProcess.Visibility, 999 | ) 1000 | existsInTarget := strconv.FormatBool(repoToProcess.ExistsInTarget) 1001 | if !repoToProcess.ExistsInTarget { 1002 | existsInTarget = Red(existsInTarget) 1003 | } else if repoToProcess.Visibility != TargetRepositories[tIdx].Visibility { 1004 | visiblity = fmt.Sprintf( 1005 | "%s|%s", 1006 | visiblity, 1007 | Yellow(repoToProcess.TargetVisibility), 1008 | ) 1009 | } 1010 | ResultsTable = append(ResultsTable, []string{ 1011 | repoToProcess.NameWithOwner, 1012 | existsInTarget, 1013 | repoToProcess.DefaultBranchRef.Name, 1014 | strings.ToLower(visiblity), 1015 | fmt.Sprintf("%d", secretsResponse.Total_Count), 1016 | fmt.Sprintf("%d", variablesResponse.Total_Count), 1017 | fmt.Sprintf("%d", envResponse.Total_Count), 1018 | }) 1019 | 1020 | SleepIfLongerThan(start) 1021 | 1022 | // close out this thread 1023 | WaitGroup.Done() 1024 | } 1025 | 1026 | func GetSourceRepositories() { 1027 | repositoryQueryResults, err := GetRepositories( 1028 | SourceRestClient, 1029 | SourceGraphqlClient, 1030 | GithubSourceOrg, 1031 | ) 1032 | if err != nil { 1033 | ExitManual(err) 1034 | } 1035 | SourceRepositories = repositoryQueryResults 1036 | WaitGroup.Done() 1037 | } 1038 | 1039 | func GetTargetRepositories() { 1040 | repositoryQueryResults, err := GetRepositories( 1041 | TargetRestClient, 1042 | TargetGraphqlClient, 1043 | GithubTargetOrg, 1044 | ) 1045 | if err != nil { 1046 | ExitManual(err) 1047 | } 1048 | TargetRepositories = repositoryQueryResults 1049 | WaitGroup.Done() 1050 | } 1051 | 1052 | func GetRepositories( 1053 | restClient api.RESTClient, 1054 | graphqlClient api.GQLClient, 1055 | owner string, 1056 | ) ([]repository, error) { 1057 | 1058 | repoLookup := []repository{} 1059 | query := repositoryQuery{} 1060 | var err error 1061 | 1062 | // get our variables set up for the graphql query 1063 | variables := map[string]interface{}{ 1064 | "owner": graphql.String(owner), 1065 | "page": (*graphql.String)(nil), 1066 | } 1067 | 1068 | // Loop through pages of repositories, waiting 1 second in between 1069 | var i = 1 1070 | for { 1071 | 1072 | // validate we have API attempts left 1073 | _, err := ValidateApiRate(restClient, "graphql") 1074 | if err != nil { 1075 | OutputError(err.Error(), true) 1076 | } 1077 | 1078 | // show a suffix next to the spinner for what we are curretnly doing 1079 | DebugAndStatus( 1080 | fmt.Sprintf( 1081 | "Fetching repositories from organization '%s' (page %d)", 1082 | owner, 1083 | i, 1084 | ), 1085 | ) 1086 | 1087 | // make the graphql request 1088 | graphqlClient.Query("RepoList", &query, variables) 1089 | 1090 | // clone the objects (keeping just the name) 1091 | for _, repoNode := range query.Organization.Repos.Nodes { 1092 | var repoClone repository 1093 | repoClone.Name = repoNode.Name 1094 | repoClone.Owner = repoNode.Owner.Login 1095 | repoClone.NameWithOwner = repoNode.NameWithOwner 1096 | repoClone.Visibility = repoNode.Visibility 1097 | repoClone.DefaultBranchRef = repoNode.DefaultBranchRef 1098 | repoLookup = append(repoLookup, repoClone) 1099 | } 1100 | 1101 | Debug( 1102 | fmt.Sprintf( 1103 | "GraphQL Repository Query Response: %+v", 1104 | query.Organization.Repos, 1105 | ), 1106 | ) 1107 | 1108 | // if no next page is found, break 1109 | if !query.Organization.Repos.PageInfo.HasNextPage { 1110 | break 1111 | } 1112 | i++ 1113 | 1114 | // set the end cursor for the page we are on 1115 | variables["page"] = query.Organization.Repos.PageInfo.EndCursor 1116 | } 1117 | 1118 | return repoLookup, err 1119 | } 1120 | 1121 | func ProcessIssues( 1122 | client api.RESTClient, 1123 | targetOrg string, 1124 | reposToProcess []repository, 1125 | ) (err error) { 1126 | 1127 | for _, repository := range reposToProcess { 1128 | 1129 | var issuesResponse issues 1130 | 1131 | if !repository.ExistsInTarget { 1132 | Debug( 1133 | fmt.Sprintf( 1134 | "Skipped %s because it did not exist in the target org.", 1135 | repository.Name, 1136 | ), 1137 | ) 1138 | continue 1139 | } 1140 | 1141 | // validate rate 1142 | _, err := ValidateApiRate(client, "core") 1143 | if err != nil { 1144 | return err 1145 | } 1146 | 1147 | query := url.QueryEscape( 1148 | fmt.Sprintf( 1149 | "%s repo:%s/%s in:title state:open", 1150 | DefaultIssueTitleTemplate, 1151 | targetOrg, 1152 | repository.Name, 1153 | ), 1154 | ) 1155 | Debug(fmt.Sprintf("Using search string: %s", query)) 1156 | DebugAndStatus( 1157 | fmt.Sprintf( 1158 | "Searching issues in %s/%s", 1159 | targetOrg, 1160 | repository.Name, 1161 | ), 1162 | ) 1163 | err = client.Get( 1164 | fmt.Sprintf( 1165 | "search/issues?q=%s", 1166 | query, 1167 | ), 1168 | &issuesResponse, 1169 | ) 1170 | Debug(fmt.Sprintf("Response from GET: %+v", issuesResponse)) 1171 | 1172 | if err != nil { 1173 | return err 1174 | } 1175 | 1176 | // validate rate 1177 | _, err = ValidateApiRate(client, "core") 1178 | if err != nil { 1179 | return err 1180 | } 1181 | 1182 | // start timer 1183 | start := time.Now() 1184 | 1185 | // use json marshal indention for JSON 1186 | varIndented, _ := json.MarshalIndent(repository.Variables, "", " ") 1187 | secIndented, _ := json.MarshalIndent(repository.Secrets, "", " ") 1188 | envIndented, _ := json.MarshalIndent(repository.Environments, "", " ") 1189 | 1190 | // set some time zone info 1191 | now := time.Now() 1192 | tz, _ := now.Zone() 1193 | 1194 | // create a template 1195 | issueTemplate := `# Audit Results 1196 | Audit last performed on %s at %s %s. 1197 | 1198 | See below for migration details and whether you need to mitigate any items. 1199 | 1200 | ## Details 1201 | - **Migrated From:** [%s](https://github.com/%s) 1202 | - **Source Visibility:** [%s](https://github.com/%s/settings/#danger-zone) 1203 | 1204 | ## Items From Source 1205 | ### [Variables](https://github.com/%s/settings/secrets/actions) 1206 | 1207 | %s 1208 | ### [Secrets](https://github.com/%s/settings/secrets/variables) 1209 | 1210 | %s 1211 | ### [Environments](https://github.com/%s/settings/environments) 1212 | 1213 | %s 1214 | ## LFS Detection 1215 | *Only accounts for %s branch.* 1216 | 1217 | %s` 1218 | 1219 | // build a string for LFS output ahead of time 1220 | decodedLFS, foundLFS, _ := LFSExists(repository.LFS.Content) 1221 | lfsString := "No LFS declaration detected in `.gitattributes`\n" 1222 | if foundLFS { 1223 | lfsString = "Validate the paths referenced in `.gitattributes`:\n" 1224 | lfsString += "```\n" 1225 | lfsString += string(decodedLFS) 1226 | lfsString += "```\n" 1227 | } 1228 | 1229 | // replace values in template 1230 | newRepoAndOwner := fmt.Sprint(targetOrg, "/", repository.Name) 1231 | issueBody := fmt.Sprintf( 1232 | issueTemplate, 1233 | now.Format("2006-01-02"), 1234 | now.Format("15:04:05"), 1235 | tz, 1236 | repository.Owner, 1237 | repository.NameWithOwner, 1238 | strings.ToLower(repository.Visibility), 1239 | newRepoAndOwner, 1240 | newRepoAndOwner, 1241 | fmt.Sprint("```\n", string(varIndented), "\n```"), 1242 | newRepoAndOwner, 1243 | fmt.Sprint("```\n", string(secIndented), "\n```"), 1244 | newRepoAndOwner, 1245 | fmt.Sprint("```\n", string(envIndented), "\n```"), 1246 | repository.DefaultBranchRef.Name, 1247 | lfsString, 1248 | ) 1249 | 1250 | if issuesResponse.Total_Count == 1 { 1251 | 1252 | var updateResponse interface{} 1253 | // find issue number 1254 | foundIssue := issuesResponse.Items[0] 1255 | // update an issue 1256 | updateBody, err := json.Marshal(map[string]string{ 1257 | "body": issueBody, 1258 | }) 1259 | if err != nil { 1260 | return err 1261 | } 1262 | updateUrl := fmt.Sprintf( 1263 | "repos/%s/%s/issues/%d", 1264 | targetOrg, 1265 | repository.Name, 1266 | foundIssue.Number, 1267 | ) 1268 | DebugAndStatus(fmt.Sprintf("Updating issue on %s", updateUrl)) 1269 | err = client.Patch( 1270 | updateUrl, 1271 | bytes.NewBuffer(updateBody), 1272 | updateResponse, 1273 | ) 1274 | if err != nil { 1275 | return err 1276 | } 1277 | Debug(fmt.Sprintf("Response from PATCH: %+v", updateResponse)) 1278 | 1279 | } else if issuesResponse.Total_Count == 0 { 1280 | 1281 | var createResponse interface{} 1282 | // create an issue 1283 | createBody, err := json.Marshal(map[string]string{ 1284 | "title": DefaultIssueTitleTemplate, 1285 | "body": issueBody, 1286 | }) 1287 | if err != nil { 1288 | return err 1289 | } 1290 | createUrl := fmt.Sprintf( 1291 | "repos/%s/%s/issues", 1292 | targetOrg, 1293 | repository.Name, 1294 | ) 1295 | DebugAndStatus(fmt.Sprintf("Creating issue on %s", createUrl)) 1296 | err = client.Post( 1297 | createUrl, 1298 | bytes.NewBuffer(createBody), 1299 | createResponse, 1300 | ) 1301 | if err != nil { 1302 | return err 1303 | } 1304 | Debug(fmt.Sprintf("Response from POST: %+v", createResponse)) 1305 | 1306 | } else { 1307 | 1308 | // when more than 1 issue is found 1309 | Debug(fmt.Sprint( 1310 | "Could not accurately determine issue to update because multiple ", 1311 | fmt.Sprintf( 1312 | "issues with the title '%s' were found.", 1313 | DefaultIssueTitleTemplate, 1314 | ), 1315 | )) 1316 | } 1317 | 1318 | SleepIfLongerThan(start) 1319 | } 1320 | 1321 | return err 1322 | } 1323 | 1324 | func ProcessRepositoryVisibilities( 1325 | client api.RESTClient, 1326 | targetOrg string, 1327 | reposToProcess []repository, 1328 | ) (err error) { 1329 | 1330 | var response interface{} 1331 | for _, repository := range reposToProcess { 1332 | 1333 | // validate rate 1334 | _, err := ValidateApiRate(client, "core") 1335 | if err != nil { 1336 | return err 1337 | } 1338 | 1339 | // create json body 1340 | requestbody, err := json.Marshal(map[string]string{ 1341 | "visibility": strings.ToLower(repository.Visibility), 1342 | }) 1343 | if err != nil { 1344 | return err 1345 | } 1346 | 1347 | // start timer 1348 | start := time.Now() 1349 | 1350 | // perform request 1351 | DebugAndStatus( 1352 | fmt.Sprintf( 1353 | "Patching %s/%s with visibility '%s'", 1354 | targetOrg, 1355 | repository.NameWithOwner, 1356 | strings.ToLower(repository.Visibility), 1357 | ), 1358 | ) 1359 | err = client.Patch( 1360 | fmt.Sprintf( 1361 | "repos/%s/%s", 1362 | targetOrg, 1363 | repository.Name, 1364 | ), 1365 | bytes.NewBuffer(requestbody), 1366 | &response, 1367 | ) 1368 | Debug(fmt.Sprintf("Response from PATCH: %+v", response)) 1369 | if err != nil { 1370 | return err 1371 | } 1372 | 1373 | SleepIfLongerThan(start) 1374 | } 1375 | 1376 | // always return 1377 | return err 1378 | } 1379 | --------------------------------------------------------------------------------