NickLiffen / ghas-enablement

A tool that aims to bulk automates the enablement of GitHub Code Scanning, Secret Scanning and Dependabot across multiple repositories.
152 stars 52 forks source link

HTTP error when using in github Actions mode #91

Open reubensamuel opened 1 year ago

reubensamuel commented 1 year ago

Hi Nick

We are using the last option with action workflow file when i run the action we get the following issue any help would be highly appreciated

Run npm run getRepos

> github-helper@1.0.0 getRepos
> npm run build && node ./lib/getRepos.js

> github-helper@1.0.0 build
> npx tsc

2022-12-01T12:42:20.944Z ghas:inform Could not find file: ./bin/organizations.json. Assuming no organizations have been collected.
2022-12-01T12:42:20.945Z ghas:inform Collecting repositories for XXXX
2022-12-01T12:42:20.945Z ghas:inform This is org number 1 of 1
2022-12-01T12:42:21.689Z ghas:error HttpError: Not Found
    at /home/runner/work/ghas-enablement/ghas-enablement/node_modules/@octokit/request/dist-node/index.js:86:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getInstallationAuthentication (/home/runner/work/ghas-enablement/ghas-enablement/node_modules/@octokit/auth-app/dist-node/index.js:280:7)
    at async hook (/home/runner/work/ghas-enablement/ghas-enablement/node_modules/@octokit/auth-app/dist-node/index.js:449:7)
    at async Job.doExecute (/home/runner/work/ghas-enablement/ghas-enablement/node_modules/bottleneck/light.js:405:[18](https://github.com/HDRUK/ghas-enablement/actions/runs/3592684492/jobs/6048693035#step:4:19))

Thanks reuben

NickLiffen commented 1 year ago

Hey @reubensamuel 👋

It looks like you haven't set the right environment variables 👀

The reason why I say this is due to this line:

2022-12-01T12:42:20.945Z ghas:inform Collecting repositories for XXXX

What did you set GITHUB_ORG to 🤔

reubensamuel commented 1 year ago

Hi Nick , I have blurred the organisation for confidentiality but it does pick up the org name from the variable GITHUB_ORG This is org number 1 of 1 . It seems to be failing here:

const repositoriesInOrg = (await func(
    res[index].login,
    graphQuery
)) as usersWriteAdminReposArray;

res[index].repos = repositoriesInOrg;
}

Does the user below require admin access to github ?

git config --global user.name "ghas-enablement"
git config --global user.email "ghas.enablement@example.com"

Thanks

Reuben

benhorgen commented 1 year ago

I ran into a similar issue when I updated my repos.json file manually and accidentally used the full repo URL (e.g included full FQDN path prefixed with https://...) rather than just the subpath my-org/my-repo

For example I had a line like this in my 'repos.json' file:

"repo": "https://github.com/benhorgen/ghas-bootcamp-benhorgen"

when I should have had this:

"repo": "benhorgen/ghas-bootcamp-benhorgen"

Full example:

[
    {
        "login": "benhorgen",
        "repos": [
            {
                "enableDependabot": false,
                "enableDependabotUpdates": false,
                "enableSecretScanning": true,
                "enableCodeScanning": true,
                "enablePushProtection": true,
                "primaryLanguage": "python",
                "createIssue": true,
                "repo": "benhorgen/ghas-bootcamp-benhorgen"
            }
        ]
    }
]
reubensamuel commented 1 year ago

Thanks Benhorgen, I have the right repo format too. Did you have to manually create the repos.json file ? I tried creating a repos.json file it said for public repos ghas is enabled automatically but for private repos asked to purchase enterprise. But doesn't configure code scanning on the public repo even though it was set to true :s . Also i tried with github app approach got Http error . Gave up on it getting it done through github apps Then i made use of PAT which worked but then above issues where we couldn't configure anything just enable. There are too many moving parts here maybe config of app or PAT could be added to the readme

Thanks Reuben

reubensamuel commented 1 year ago

In github apps configuration could not understand the difference between APP_ID: ${{ secrets.GHAS_ENABLEMENT_APP_ID }} and APP_INSTALLATION_ID: "12345678" are they different where could i find these details

joshjohanning commented 1 year ago

In github apps configuration could not understand the difference between APP_ID: ${{ secrets.GHAS_ENABLEMENT_APP_ID }} and APP_INSTALLATION_ID: "12345678" are they different where could i find these details

@reubensamuel The app id is visible when you are editing your GitHub app, such as:

image

For the installation ID, I find it easiest by going to my org's installed apps and clicking on your app. The installation ID will be in the address bar

image