octokit / rest.js

GitHub REST API client for JavaScript
https://octokit.github.io/rest.js
MIT License
525 stars 62 forks source link

[BUG]: createRepoVariable 401 #431

Closed austenstone closed 1 month ago

austenstone commented 1 month ago

What happened?

I can't understand why but I can't call createRepoVariable without getting a 401.

          await octokit.rest.actions.createRepoVariable({
            ...ownerRepo,
            name: variableName(context.workflow, inputDate),
            value: context.ref,
          });

This works just fine...

          fetch('https://api.github.com/repos/austenstone/schedule/actions/variables', {
            method: 'POST',
            headers: {
              'Authorization': `token ${inputs.token}`,
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({
              name: variableName(context.workflow, inputDate),
              value: context.ref,
            }),
          });

Versions

    "node_modules/@actions/github": {
      "version": "6.0.0",
      "license": "MIT",
      "dependencies": {
        "@actions/http-client": "^2.2.0",
        "@octokit/core": "^5.0.1",
        "@octokit/plugin-paginate-rest": "^9.0.0",
        "@octokit/plugin-rest-endpoint-methods": "^10.0.0"
      }
    },

Relevant log output

Error creating variable {
  "name": "HttpError",
  "status": 401,
  "response": {
    "url": "https://api.github.com/repos/austenstone/schedule/actions/variables",
    "status": 401,
    "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",
      "content-length": "80",
      "content-security-policy": "default-src 'none'",
      "content-type": "application/json; charset=utf-8",
      "date": "Sat, 11 May 2024 15:05:39 GMT",
      "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
      "server": "GitHub.com",
      "strict-transport-security": "max-age=31536000; includeSubdomains; preload",
      "vary": "Accept-Encoding, Accept, X-Requested-With",
      "x-content-type-options": "nosniff",
      "x-frame-options": "deny",
      "x-github-media-type": "github.v3; format=json",
      "x-github-request-id": "3882:233D60:63D475C:A435470:663F8943",
      "x-ratelimit-limit": "60",
      "x-ratelimit-remaining": "59",
      "x-ratelimit-reset": "1715443539",
      "x-ratelimit-resource": "core",
      "x-ratelimit-used": "1",
      "x-xss-protection": "0"
    },
    "data": {
      "message": "Bad credentials",
      "documentation_url": "https://docs.github.com/rest"
    }
  },
  "request": {
    "method": "POST",
    "url": "https://api.github.com/repos/austenstone/schedule/actions/variables",
    "headers": {
      "accept": "application/vnd.github.v3+json",
      "user-agent": "octokit-core.js/5.1.0 Node.js/20.8.1 (linux; x64)",
      "authorization": "token [REDACTED]",
      "content-type": "application/json; charset=utf-8"
    },
    "body": "{\"name\":\"_schedule_Schedule_1715644800000\",\"value\":\"refs/heads/main\"}",
    "request": {
      "agent": {
        "_events": {},
        "_eventsCount": 2,
        "defaultPort": 443,
        "protocol": "https:",
        "options": {
          "keepAlive": true,
          "scheduling": "lifo",
          "timeout": 5000,
          "noDelay": true,
          "path": null
        },
        "requests": {},
        "sockets": {},
        "freeSockets": {},
        "keepAliveMsecs": 1000,
        "keepAlive": true,
        "maxSockets": null,
        "maxFreeSockets": 256,
        "scheduling": "lifo",
        "maxTotalSockets": null,
        "totalSocketCount": 0,
        "maxCachedSessions": 100,
        "_sessionCache": {
          "map": {},
          "list": []
        }
      }
    }
  }
}

Code of Conduct

github-actions[bot] commented 1 month ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

wolfy1339 commented 1 month ago

Can you test directly with @octokit/rest you are using @actions/github?

austenstone commented 1 month ago

nvm this is my fault. I'm using the wrong token