codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

HTTP 401: You are not authorized for this action #342

Closed julianguyen closed 6 years ago

julianguyen commented 6 years ago

Anyone know where this is coming from? I have the correct test report ID.

Ran all test suites.
Done in 37.00s.
Error: response from https://api.codeclimate.com/v1/test_reports.
HTTP 401: You are not authorized for this action
Usage:
  cc-test-reporter after-build [flags]

Flags:
  -s, --batch-size int               batch size for source files (default 500)
  -e, --coverage-endpoint string     endpoint to upload coverage information to (default "https://api.codeclimate.com/v1/test_reports")
  -t, --coverage-input-type string   type of input source to use [clover, cobertura, coverage.py, excoveralls, gcov, gocov, jacoco, lcov, simplecov]
      --exit-code int                exit code of the test run
  -r, --id string                    reporter identifier (default "${TEST_REPORTER_ID}")
      --insecure                     send coverage insecurely (without HTTPS)
  -p, --prefix string                the root directory where the coverage analysis was performed (default "/root/hs-b2b-dashboard")

Global Flags:
  -d, --debug   run in debug mode

Exited with code 255

EDIT: In debug mode I get:

DEBU[0000] about to run upload-coverage                 
DEBU[0000] posting request to https://api.codeclimate.com/v1/test_reports 
DEBU[0000] {"data":{"type":"test_reports","attributes":{"ci_branch":"set-up-code-climate","ci_build_identifier":"363","ci_build_url":"363","ci_commit_sha":"[hidden]","ci_committed_at":1528238506,"ci_service_name":"true","git_branch":"set-up-code-climate","commit_sha":"[hidden]","committed_at":1528238506,"run_at":1528238616,"covered_percent":77.05263157894737,"covered_strength":0,"environment":{"gem_version":"","package_version":"","pwd":"/root/[hidden]","prefix":"/root/[hidden]","rails_root":"","reporter_version":"0.6.0","simplecov_root":""},"line_counts":{"missed":327,"covered":1098,"total":1425}}},"meta":null}

DEBU[0000] {"errors":[{"detail":"You are not authorized for this action","title":"Unauthorized"}]} 
Error: response from https://api.codeclimate.com/v1/test_reports.
HTTP 401: You are not authorized for this action
Usage:
  cc-test-reporter after-build [flags]
maxjacobson commented 6 years ago

Hi Julia,

Thanks for providing the debug mode output. Hmm. I think you should only see that error if we can't find the repository based on the provided test report id. Do you mind sharing a bit about your CI setup, specifically how you're setting the CC_TEST_REPORTER_ID environment variable?

AlexGrs commented 6 years ago

Same issue for us.

CC_TEST_REPORTER_ID is set correctly, taken from the setting of our codecov account. We followed the documentation of test-reporter but it fails.

maxjacobson commented 6 years ago

@AlexGrs - Will you also share a bit about your CI setup, specifically how you're setting the environment variable? I'd love to see an excerpt from your .travis.yml or circle.yml (or similar)

2YY commented 6 years ago

I faced same issue and my config.yml is below.

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    environment:
      CC_TEST_REPORTER_ID: $CODE_CLIMATE_TEST_REPORTER_ID
    docker:
      # specify the version you desire here
      - image: circleci/node:7.10

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      # install java 8
      - run: echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 boolean true" > debconf.txt
      - run: sudo debconf-set-selections debconf.txt
      - run: sudo apt-get install software-properties-common
      - run: sudo add-apt-repository "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main"
      - run: sudo apt-get update
      - run: sudo apt-get install oracle-java8-installer

      # Setup Code Climate test-reporter
      - run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
      - run: chmod +x ./cc-test-reporter

      # load CircleCI environment variables
      - run: export GOOGLE_API_KEY=$GOOGLE_API_KEY

      # run tests!
      - run: npm test

      # Send test coverage to Code Climate
      - run: ./cc-test-reporter after-build --coverage-input-type lcov --exit-code $?
efueger commented 6 years ago

Following up on these. @julianguyen :

@2YY :

2YY commented 6 years ago

@efueger Thanks efueger.

I merged into master and got same error from CircleCI.

HTTP 401: You are not authorized for this action

The CircleCI build is here. https://circleci.com/gh/2YY/qatool/31

I think, this problem has a concern in the CircleCI Environment.

If I config CC_TEST_REPORTER_ID by hard coding, build is pass. https://circleci.com/gh/2YY/qatool/19

But, if I config CC_TEST_REPORTER_ID by CircleCI Environment Variable, build is fail. https://circleci.com/gh/2YY/qatool/20

efueger commented 6 years ago

Thanks @2YY -

On master, can you:

  1. remove the hard coded CC_TEST_REPORTERID env var lines in your config.yml (lines 8 and 9)_
  2. change the var name in your CircleCI Environmental Variable to CC_TEST_REPORTER_ID

Let me know how it goes!

2YY commented 6 years ago

@efueger Hi efueger!

I tried that and seems like same result.

The CircleCI build is here. https://circleci.com/gh/2YY/qatool/32

I tried below steps. Please correct me if I'm wrong.

  1. Change the var name to CC_TEST_REPORTER_ID in my .circleci/config.yml The commit is here. https://github.com/2YY/qatool/commit/8bcfacc16a2e7e93a62494eb4a38d54edacd6eac

  2. Add CircleCI environmental variable CC_TEST_REPORTER_ID in my CircleCI project configration (like below capture) 2018-07-07 1 37 48

efueger commented 6 years ago

Almost! Can you delete the reference for the environment var in your .circleci/config.yml?

2YY commented 6 years ago

@efueger Great, works perfectly!!

My problem is solved.

Thank you for your support efueger! 2018-07-07 2 02 27

chidioguejiofor commented 6 years ago

@efueger thanks a lot for helping out @2YY. It solved my own problem as well .

Guess you killed many birds with one stone

chadwalt commented 5 years ago

@efueger thanks, this was helpful. I had the same issue.

madeofhuman commented 5 years ago

@efueger thanks a lot for helping out @2YY. It solved my own problem as well .

Guess you killed many birds with one stone

HAHAHAHA!!!!

lilithxxx commented 5 years ago

On master, can you: remove the hard coded CC_TEST_REPORTER_ID env var lines in your config.yml (lines 8 and 9) change the var name in your CircleCI Environmental Variable to CC_TEST_REPORTER_ID

@efueger is merging the changes into master necessary? How can I set up coverage from a feature branch?