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

Fix getting diffs from Bitbucket Server #871

Merged
merged 5 commits into from
Sep 24, 2019

Conversation

osmestad
Copy link
Contributor

@osmestad osmestad commented Jun 6, 2019

For getting a diff from the Bitbucket Server API it seems the from and to commit hashes were switched. This should solve #866, and other APIs that depend on the getStructuredDiffForFile method.

@orta
Copy link
Member

orta commented Jun 6, 2019

This CII failure is the same issue in #870 and not your issue

@osmestad
Copy link
Contributor Author

osmestad commented Jun 6, 2019

Cool, I did see some of those errors locally as well, the:

source/commands/utils/chainsmoker.ts:40:7 - error TS2698: Spread types may only be created from object types.
40       ...mapValues(keyedPaths, (paths: Path[]) => paths.length > 0),
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When running tests after doing a yarn run link I think, if that is of any help for that issue :-)

@orta
Copy link
Member

orta commented Jun 6, 2019

Interesting! I can't get that to occur on my setup on master

orta@Perl ~/d/d/danger-js> git pull origin master
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 49 (delta 31), reused 37 (delta 29), pack-reused 6
Unpacking objects: 100% (49/49), done.
From https://github.com/danger/danger-js
 * branch            master     -> FETCH_HEAD
   e4b6cfa..a1db4c6  master     -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
Updating e4b6cfa..a1db4c6
Fast-forward
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
 CHANGELOG.md                            | 11 ++++++---
 README.md                               |  2 +-
 package.json                            |  2 +-
 source/ci_source/providers/AppCenter.ts | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 source/ci_source/providers/index.ts     |  3 +++
 source/platforms/github/GitHubUtils.ts  | 12 +++++-----
 6 files changed, 94 insertions(+), 11 deletions(-)
 create mode 100644 source/ci_source/providers/AppCenter.ts

 orta@Perl ~/d/d/danger-js> rm -rf node_modules/; yarn
yarn install v1.16.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
✨  Done in 13.52s.
orta@Perl ~/d/d/danger-js> yarn build
yarn run v1.16.0
$ shx rm -rf ./distribution && tsc -p tsconfig.production.json && madge ./distribution --circular
Processed 101 files (1.7s)

✔ No circular dependency found!

✨  Done in 6.89s.

orta@Perl ~/d/d/danger-js> yarn jest
yarn run v1.16.0
$ /Users/orta/dev/danger/danger-js/node_modules/.bin/jest
 PASS  source/runner/templates/_tests/_githubIssueTemplates.test.ts (8.6s)
 PASS  source/dsl/_tests/DangerResults.test.ts (8.706s)
 PASS  source/api/_tests/fetch.test.ts (8.844s)
 PASS  source/platforms/github/_tests/_customGitHubRequire.test.ts (9.048s)
 PASS  source/runner/templates/_tests/_bitbucketServerTemplate.test.ts
(node:44109) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
 PASS  source/platforms/bitbucket_server/_tests/_bitbucket_server_api.test.ts (9.408s)
 PASS  source/platforms/_tests/_bitbucket_server.test.ts
(node:44111) UnhandledPromiseRejectionWarning: undefined
(node:44111) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:44111) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:44111) UnhandledPromiseRejectionWarning: undefined
(node:44111) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
 PASS  source/platforms/bitbucket_server/_tests/_bitbucket_server_git.test.ts (10.452s)
 PASS  source/platforms/_tests/_github.test.ts (10.734s)
(node:44110) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
 PASS  source/platforms/github/_tests/_github_api.test.ts (10.77s)
 PASS  source/ci_source/providers/_tests/_teamcity.test.ts
 PASS  source/ci_source/providers/_tests/_circle.test.ts
 PASS  source/ci_source/providers/_tests/_vsts.test.ts
 PASS  source/ci_source/providers/_tests/_jenkins.test.ts
 PASS  source/ci_source/providers/_tests/_travis.test.ts
 PASS  source/ci_source/providers/_tests/_semaphore.test.ts
 PASS  source/runner/runners/_tests/_cleanDangerfile.test.ts
 PASS  source/ci_source/providers/_tests/_buddyBuild.test.ts
 PASS  source/ci_source/providers/_tests/_codebuild.test.ts
 PASS  source/ci_source/providers/_tests/_dockerCloud.test.ts
 PASS  source/ci_source/providers/_tests/_netlify.test.ts
 PASS  source/ci_source/providers/_tests/_buildkite.test.ts
 PASS  source/ci_source/providers/_tests/_codefresh.test.ts
 PASS  source/ci_source/providers/_tests/_screwdriver.test.ts
 PASS  source/commands/utils/_tests/dangerRunToRunnerCLI.test.ts
 PASS  source/runner/_tests/jsonToContext.test.ts
 PASS  source/ci_source/providers/_tests/_concourse.test.ts
 PASS  source/ci_source/providers/_tests/_bitrise.test.ts
 PASS  source/commands/ci/_tests/runner.test.ts (11.715s)
 PASS  source/platforms/github/_tests/_github_utils.test.ts
 PASS  source/ci_source/providers/_tests/_drone.test.ts
 PASS  source/commands/utils/_tests/chainsmoker.test.ts
 PASS  source/platforms/_tests/_pull_request_parser.test.ts
 PASS  source/platforms/github/comms/_tests/_checksCommenter.test.ts
 PASS  source/commands/utils/_tests/file-utils.test.ts
 PASS  source/runner/_tests/_danger_utils.test.ts
 PASS  source/ci_source/providers/_tests/_nevercode.test.ts
 PASS  source/ci_source/_tests/_get_ci_source.test.ts
  ● Console

    console.error source/ci_source/get_ci_source.ts:30
      could not load CI provider at ./dummy_ci.js due to Error: ENOENT: no such file or directory, stat '/Users/orta/dev/danger/danger-js/dummy_ci.js'

 PASS  source/platforms/git/_tests/localGetCommits.test.ts
 PASS  source/runner/templates/_tests/_markdownTableTemplate.test.ts
 PASS  source/platforms/_tests/_platform.test.ts
  ● Console

    console.error source/platforms/platform.ts:132
      The DANGER_GITHUB_API_TOKEN/DANGER_BITBUCKETSERVER_HOST environmental variable is missing
    console.error source/platforms/platform.ts:133
      Without an api token, danger will be unable to comment on a PR

 PASS  source/runner/runners/utils/_tests/_transpiler.test.ts
(node:44107) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
 PASS  source/platforms/github/_tests/_github_git.test.ts (12.849s)
 PASS  source/runner/_tests/_executor.test.ts (12.979s)
 PASS  source/platforms/github/comms/_tests/_issueCommenter.test.ts
 PASS  source/runner/_tests/jsonToDSL.test.ts

Test Suites: 46 passed, 46 total
Tests:       1 skipped, 442 passed, 443 total
Snapshots:   44 passed, 44 total
Time:        14.549s
Ran all test suites.
✨  Done in 19.77s.
orta@Perl ~/d/d/danger-js>

@osmestad
Copy link
Contributor Author

osmestad commented Jun 7, 2019

The steps that make it fail for me in a clean folder are:

  1. git clone https://github.com/danger/danger-js.git .
  2. yarn install
  3. yarn run link
  4. yarn jest

Which then ends with:

 FAIL  source/runner/_tests/jsonToDSL.test.ts
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    source/commands/utils/chainsmoker.ts:40:7 - error TS2698: Spread types may only be created from object types.

    40       ...mapValues(keyedPaths, (paths: Path[]) => paths.length > 0),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Test Suites: 30 failed, 17 passed, 47 total

Let me know if you want the full console output :-)

@orta
Copy link
Member

orta commented Jun 7, 2019

Thanks!
looks like that also adds a package-lock.json - wonder if running npm link triggers an npm install which ignores the (yarn) lockfile

@orta
Copy link
Member

orta commented Jun 7, 2019

Think I fixed this in 71667ad

<edit> ... or not

@josete89
Copy link

josete89 commented Jun 11, 2019

I had the same issue with bitbucket server, but when I tried the changes proposed by the pr. I'm getting the following error:

Danger: ⅹ Failing the build, there is 1 fail.
## Failures
 Error : invalid json response body at https://tools.com/bitbucket/rest/api/1.0/projects/PRJ/repos/prj-session/compare/diff/package-lock in JSON at position 1096011, stacktrace: FetchError: invalid json response body at https://tools.com/bitbucket/rest/api/1.0/projects/PRJ/repos/prj-session/compare/diff/package-lock.json?withComments=false&from=1a2c1fccaaaca7e8d54e9dc99c7709d9dd88595f&to=4c595cded974df724a871d77645ca28655bf2b3e in JSON at position 1096011
    at /Users/josete89/Projects/PRJ/prj-session/node_modules/node-fetch/lib/index.js:241:32
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

@osmestad
Copy link
Contributor Author

Could that be the diff being too big? (package-lock.json changes can be many I guess) I saw there was some discussion about paged results from the API somewhere. Cut at 1MB maybe? I'm guessing here :-)
If you load the API request in a browser (with a JSON viewer extension) you might be able to see some details. One thing I was considering was if we could strip away the context lines to make the responses smaller, but I was a bit unsure if they were used anywhere, you can test that by appending: &contextLines=0 to the API request URL

@pajapro
Copy link

pajapro commented Jul 10, 2019

Any update on this PR @orta @osmestad ?

@HonzaMac
Copy link

Could that be the diff being too big? (package-lock.json changes can be many I guess) I saw there was some discussion about paged results from the API somewhere. Cut at 1MB maybe? I'm guessing here :-)
If you load the API request in a browser (with a JSON viewer extension) you might be able to see some details. One thing I was considering was if we could strip away the context lines to make the responses smaller, but I was a bit unsure if they were used anywhere, you can test that by appending: &contextLines=0 to the API request URL

It was happening even for simple diffs

@platan
Copy link

platan commented Sep 24, 2019

I've tested this change and it works properly for me. Can I somehow help with this PR?

@orta
Copy link
Member

orta commented Sep 24, 2019

Well, this looks like an improvement to me - so let's get it in

@orta orta merged commit 2009766 into danger:master Sep 24, 2019
@peril-staging
Copy link
Contributor

peril-staging bot commented Sep 24, 2019

Thanks for the PR @osmestad.

The Danger org conform to the Moya Community Continuity Guidelines, which means
that we want to offer any contributor the ability to control their destiny.

So, we've sent you an org invite - thanks osmestad 🎉

Generated by 🚫 dangerJS against 9f1d81d

@HonzaMac
Copy link

👏👏👏👏
Thank you!

Let’s ship it 🚀

@osmestad
Copy link
Contributor Author

Great to get it in!

@osmestad osmestad deleted the fix-bitbucket-server-diffs branch September 25, 2019 06:21
@peril-staging
Copy link
Contributor

peril-staging bot commented Sep 25, 2019

Thanks for the PR @osmestad.

This PR has been shipped in v9.2.1 - CHANGELOG.

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.

6 participants