gavinr / github-csv-tools

Import and export GitHub issues via CSV
https://npmjs.com/github-csv-tools
MIT License
650 stars 116 forks source link

Milestone should be received as a number rather than string #90

Closed chaseoli closed 1 year ago

chaseoli commented 1 year ago

Hey @gavinr thanks for creating this repo!

Here's a quick fix to Milestones (Github expects an integer for the Milestone, not a string) and added a npm start script so users who clone your repo can run locally.

gavinr commented 1 year ago

Hi, thanks for the submission. Does this fix a particular error case? Can you post an example?

chaseoli commented 1 year ago
~/repos/github-issue-upload$ githubCsvTools import.csv -t <some-token> -o <some-org/user>-r <some-repo>
Error
RequestError [HttpError]: Invalid request.

For 'properties/milestone', "13" is not an integer or null.
    at /home/chaseo/.nvm/versions/node/v16.17.0/lib/node_modules/github-csv-tools/node_modules/@octokit/request/dist-node/index.js:86:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Job.doExecute (/home/chaseo/.nvm/versions/node/v16.17.0/lib/node_modules/github-csv-tools/node_modules/bottleneck/light.js:405:18) {
  status: 422,
  response: {
    url: 'https://api.github.com/repos/bravo6io/ft-dap/import/issues',
    status: 422,
    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-length': '146',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Tue, 27 Sep 2022 15:53:14 GMT',
      'github-authentication-token-expiration': '2022-10-03 20:59:26 UTC',
      '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-accepted-oauth-scopes': '',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-media-type': 'github.v3; format=json',
      'x-github-request-id': 'E712:30DB:233BC2F:4818EE6:63331C69',
      'x-oauth-scopes': 'repo',
      'x-ratelimit-limit': '5000',
      'x-ratelimit-remaining': '4971',
      'x-ratelimit-reset': '1664296526',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '29',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Invalid request.\n' +
        '\n' +
        `For 'properties/milestone', "13" is not an integer or null.`,
      documentation_url: 'https://docs.github.com/rest'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/bravo6io/ft-dap/import/issues',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'github-csv-tools octokit-rest.js/18.12.0 octokit-core.js/3.6.0 Node.js/16.17.0 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"issue":{"title":"test issue","body":"test body","labels":["label1","label2"],"milestone":"13"}}',
    request: { hook: [Function: bound bound register] }
  }
}

The error is related to transforming the issue milestone to a string from the CSV when it expects an integer, see error message ... "13" is not an integer or null.

gavinr commented 1 year ago

Can you please post an example CSV file that I can run with the command you posted? Thanks!

aaclayton commented 1 year ago

I am also encountering this issue, and have noticed that this problem has seemingly been active for some time: https://github.com/gavinr/github-csv-tools/issues/98

I am able to reproduce the problem using the following minimal CSV file:

title,body,labels,status,milestone
Test Import,,projectmanagement,open,3

Perhaps this PR which to me looks a pretty non-controversial one-line fix should be merged?

Might be safer to do in case the milestone value is not blank but not an integer.

          if ( (milestoneIndex > -1) && Number.isInteger(Number(row[milestoneIndex])) ) {
            sendObj.issue.milestone = Number(row[milestoneIndex]);
          }
gavinr commented 1 year ago

Thanks for the code fix. I merged this in #100.