Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Initial version #1

Merged
merged 17 commits into from
Jul 7, 2022
Merged

feat: Initial version #1

merged 17 commits into from
Jul 7, 2022

Conversation

wolfy1339
Copy link
Owner

No description provided.

Copy link

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script.js Outdated Show resolved Hide resolved
@wolfy1339
Copy link
Owner Author

It might be simpler to use https://github.com/gr2m/octokit-plugin-create-pull-request?

Indeed it is much simpler!

In order to get the file name
- Decode the content before using it
- It's Array#push() not Array#append()
- It's BREAKING CHANGE, why can't the plural also be used
@wolfy1339
Copy link
Owner Author

wolfy1339 commented Jun 28, 2022

I only seem to have one problem with the script.

The endpoint /repos/{owner}/{repository}/git/trees returns a 404 when trying to do a POST request (via octokit-plugin-create-pull-request)

Here's an extract of the log for the failed request

{
    "repository": {
        "id": 366884413,
        "owner": {
            "login": "wolfy1339",
            "id": 4595477,
            "node_id": "MDQ6VXNlcjQ1OTU0Nzc=",
            "avatar_url": "https://avatars.githubusercontent.com/u/4595477?v=4",
            "gravatar_id": "",
            "url": "https://api.github.com/users/wolfy1339",
            "html_url": "https://github.com/wolfy1339",
            "followers_url": "https://api.github.com/users/wolfy1339/followers",
            "following_url": "https://api.github.com/users/wolfy1339/following{/other_user}",
            "gists_url": "https://api.github.com/users/wolfy1339/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/wolfy1339/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/wolfy1339/subscriptions",
            "organizations_url": "https://api.github.com/users/wolfy1339/orgs",
            "repos_url": "https://api.github.com/users/wolfy1339/repos",
            "events_url": "https://api.github.com/users/wolfy1339/events{/privacy}",
            "received_events_url": "https://api.github.com/users/wolfy1339/received_events",
            "type": "User",
            "site_admin": false
        },
        "name": "test-repository"
    },
    "msg": "HttpError: Not Found\n    at /home/user/Desktop/Programming/octoherd-remove-eol-node-versions/node_modules/@octokit/request/dist-node/index.js:86:21\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async Job.doExecute (/home/user/Desktop/Programming/octoherd-remove-eol-node-versions/node_modules/bottleneck/light.js:405:18)",
    "name": "HttpError",
    "status": 404,
    "response": {
        "url": "https://api.github.com/repos/wolfy1339/test-repository/git/trees",
        "status": 404,
        "headers": {
            "access-control-allow-origin": "*",
            "access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
            "connection": "close",
            "content-encoding": "gzip",
            "content-security-policy": "default-src 'none'",
            "content-type": "application/json; charset=utf-8",
            "date": "Tue, 28 Jun 2022 16:22:38 GMT",
            "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
            "server": "GitHub.com",
            "strict-transport-security": "max-age=31536000; includeSubdomains; preload",
            "transfer-encoding": "chunked",
            "vary": "Accept-Encoding, Accept, X-Requested-With",
            "x-accepted-oauth-scopes": "",
            "x-content-type-options": "nosniff",
            "x-frame-options": "deny",
            "x-github-media-type": "github.v3; format=json",
            "x-github-request-id": "8C9A:5A0B:3870ED0:6EBC003:62BB2ACE",
            "x-oauth-scopes": "notifications, public_repo, read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user, repo:status, repo_deployment, user:email",
            "x-ratelimit-limit": "5000",
            "x-ratelimit-remaining": "4874",
            "x-ratelimit-reset": "1656433380",
            "x-ratelimit-resource": "core",
            "x-ratelimit-used": "126",
            "x-xss-protection": "0"
        },
        "data": {
            "message": "Not Found",
            "documentation_url": "https://docs.github.com/rest/reference/git#create-a-tree"
        }
    },
    "request": {
        "method": "POST",
        "url": "https://api.github.com/repos/wolfy1339/test-repository/git/trees",
        "headers": {
            "accept": "application/vnd.github.v3+json",
            "user-agent": "octoherd-cli/3.4.8 octoherd-cli/2.3.1 octokit-core.js/3.6.0 Node.js/16.15.0 (linux; x64)",
            "authorization": "token [REDACTED]",
            "content-type": "application/json; charset=utf-8"
        },
        "body": "{\"base_tree\":\"ea0e827bafdec61e54000a8631941f383f6dbdc6\",\"tree\":[{\"path\":\".github/workflows/test.yml\",\"mode\":\"100644\",\"content\":\"name: Test\\n\\\"on\\\":\\n  push:\\n    branches:\\n      - master\\n  pull_request:\\n    types:\\n      - opened\\n      - synchronize\\njobs:\\n  test_matrix:\\n    runs-on: ubuntu-latest\\n    strategy:\\n      matrix:\\n        node_version:\\n          - 14\\n          - 16\\n          - 18\\n    steps:\\n      - uses: actions/checkout@v3\\n      - name: \\\"Use Node.js ${{ matrix.node_version }}\\\"\\n        uses: actions/setup-node@v3\\n        with:\\n          node-version: \\\"${{ matrix.node_version }}\\\"\\n          cache: npm\\n      - run: npm ci\\n      - run: npm test\\n\\n  test:\\n    runs-on: ubuntu-latest\\n    needs: test_matrix\\n    steps:\\n      - uses: actions/checkout@v3\\n      - run: npm ci\\n      - run: npm run test:typescript\\n      - run: npm run lint\\n\"}]}",
        "request": {}
    },
    "level": "error",
    "time": 1656433358280
}

script.js Show resolved Hide resolved
Comment on lines +172 to +185
const pr = await composeCreatePullRequest(octokit, {
owner,
repo,
title: `ci: stop testing against NodeJS ${NODE_VERSIONS_STRING}`,
body: `BREAKING CHANGE: Drop support for NodeJS ${NODE_VERSIONS_STRING}`,
head: branchName,
changes,
createWhenEmpty: false,
update: true
});


if (pr)
octokit.log.info(`Pull request created: ${pr.data.html_url}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap this in a try-catch and ocotkit.log.error accordingly or do we want to just throw?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's warranted

@oscard0m
Copy link

oscard0m commented Jul 7, 2022

I only seem to have one problem with the script.

The endpoint /repos/{owner}/{repository}/git/trees returns a 404 when trying to do a POST request (via octokit-plugin-create-pull-request)

Here's an extract of the log for the failed request

Click to expand!
  {
  "repository": {
      "id": 366884413,
      "owner": {
          "login": "wolfy1339",
          "id": 4595477,
          "node_id": "MDQ6VXNlcjQ1OTU0Nzc=",
          "avatar_url": "https://avatars.githubusercontent.com/u/4595477?v=4",
          "gravatar_id": "",
          "url": "https://api.github.com/users/wolfy1339",
          "html_url": "https://github.com/wolfy1339",
          "followers_url": "https://api.github.com/users/wolfy1339/followers",
          "following_url": "https://api.github.com/users/wolfy1339/following{/other_user}",
          "gists_url": "https://api.github.com/users/wolfy1339/gists{/gist_id}",
          "starred_url": "https://api.github.com/users/wolfy1339/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/wolfy1339/subscriptions",
          "organizations_url": "https://api.github.com/users/wolfy1339/orgs",
          "repos_url": "https://api.github.com/users/wolfy1339/repos",
          "events_url": "https://api.github.com/users/wolfy1339/events{/privacy}",
          "received_events_url": "https://api.github.com/users/wolfy1339/received_events",
          "type": "User",
          "site_admin": false
      },
      "name": "test-repository"
  },
  "msg": "HttpError: Not Found\n    at /home/user/Desktop/Programming/octoherd-remove-eol-node-versions/node_modules/@octokit/request/dist-node/index.js:86:21\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async Job.doExecute (/home/user/Desktop/Programming/octoherd-remove-eol-node-versions/node_modules/bottleneck/light.js:405:18)",
  "name": "HttpError",
  "status": 404,
  "response": {
      "url": "https://api.github.com/repos/wolfy1339/test-repository/git/trees",
      "status": 404,
      "headers": {
          "access-control-allow-origin": "*",
          "access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
          "connection": "close",
          "content-encoding": "gzip",
          "content-security-policy": "default-src 'none'",
          "content-type": "application/json; charset=utf-8",
          "date": "Tue, 28 Jun 2022 16:22:38 GMT",
          "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
          "server": "GitHub.com",
          "strict-transport-security": "max-age=31536000; includeSubdomains; preload",
          "transfer-encoding": "chunked",
          "vary": "Accept-Encoding, Accept, X-Requested-With",
          "x-accepted-oauth-scopes": "",
          "x-content-type-options": "nosniff",
          "x-frame-options": "deny",
          "x-github-media-type": "github.v3; format=json",
          "x-github-request-id": "8C9A:5A0B:3870ED0:6EBC003:62BB2ACE",
          "x-oauth-scopes": "notifications, public_repo, read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user, repo:status, repo_deployment, user:email",
          "x-ratelimit-limit": "5000",
          "x-ratelimit-remaining": "4874",
          "x-ratelimit-reset": "1656433380",
          "x-ratelimit-resource": "core",
          "x-ratelimit-used": "126",
          "x-xss-protection": "0"
      },
      "data": {
          "message": "Not Found",
          "documentation_url": "https://docs.github.com/rest/reference/git#create-a-tree"
      }
  },
  "request": {
      "method": "POST",
      "url": "https://api.github.com/repos/wolfy1339/test-repository/git/trees",
      "headers": {
          "accept": "application/vnd.github.v3+json",
          "user-agent": "octoherd-cli/3.4.8 octoherd-cli/2.3.1 octokit-core.js/3.6.0 Node.js/16.15.0 (linux; x64)",
          "authorization": "token [REDACTED]",
          "content-type": "application/json; charset=utf-8"
      },
      "body": "{\"base_tree\":\"ea0e827bafdec61e54000a8631941f383f6dbdc6\",\"tree\":[{\"path\":\".github/workflows/test.yml\",\"mode\":\"100644\",\"content\":\"name: Test\\n\\\"on\\\":\\n  push:\\n    branches:\\n      - master\\n  pull_request:\\n    types:\\n      - opened\\n      - synchronize\\njobs:\\n  test_matrix:\\n    runs-on: ubuntu-latest\\n    strategy:\\n      matrix:\\n        node_version:\\n          - 14\\n          - 16\\n          - 18\\n    steps:\\n      - uses: actions/checkout@v3\\n      - name: \\\"Use Node.js ${{ matrix.node_version }}\\\"\\n        uses: actions/setup-node@v3\\n        with:\\n          node-version: \\\"${{ matrix.node_version }}\\\"\\n          cache: npm\\n      - run: npm ci\\n      - run: npm test\\n\\n  test:\\n    runs-on: ubuntu-latest\\n    needs: test_matrix\\n    steps:\\n      - uses: actions/checkout@v3\\n      - run: npm ci\\n      - run: npm run test:typescript\\n      - run: npm run lint\\n\"}]}",
      "request": {}
  },
  "level": "error",
  "time": 1656433358280
}

Did you find out what was the issue with this? Do you need any help on debugging/reproducing this? @wolfy1339

@wolfy1339
Copy link
Owner Author

The 404s are gone now!

There is another case of outdated node versions where it isn't in a matrix, however those can be manually fixed

@wolfy1339
Copy link
Owner Author

Here's an example of what the output is: wolfy1339/test-repository-test#10

@oscard0m
Copy link

oscard0m commented Jul 7, 2022

Here's an example of what the output is: wolfy1339/test-repository#10

LGTM!

@wolfy1339 wolfy1339 merged commit e9d31be into main Jul 7, 2022
@wolfy1339 wolfy1339 deleted the initial-version branch July 7, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants