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

Add bitbucket server support #36

Merged
merged 1 commit into from
May 19, 2016
Merged

Add bitbucket server support #36

merged 1 commit into from
May 19, 2016

Conversation

job13er
Copy link
Contributor

@job13er job13er commented May 17, 2016

This #minor# change adds bitbucket server API support.

Fixes #28

I must apologize to anyone who tries to look at the diff here. There was a major refactor that occurred during these changes, lots of logic was pulled from lib/utils.js into lib/bumper.js as well as the introduction of a ci abstraction with travis and teamcity implementations and moving some of the custom github/travis stuff from lib/vcs/github.js into the newly created lib/ci/travis.js.

The end result is that we should now have a system in place where we have a common interface between the bumper, the CI system, and the VCS system, so we (or anyone else interested) should be able to add support for say, buildbot and github-enterprise, should they so desire.

NOTE: I've confirmed this actually does work with our TeamCity and Bitbucket Server setup now by installing pr-bumper directly from my fork's branch during a CI build.

CHANGELOG

You can now configure pr-bumper to work with something other than Travis CI and GitHub. The only other configuration that has been tested is TeamCity and Bitbucket Server. You can configure pr-bumper to work with TeamCity and Bitbucket Server by placing a .pr-bumper.json file in the root of your repository and filling in some information about your CI setup:

{
  "ci": {
    "env": {
      "buildNumber": "TEAMCITY_BUILD_NUMBER",
      "pr": "TEAMCITY_PULL_REQUEST"
    },
    "gitUser": {
      "email": "ci-user",
      "name": "ci-user@my-company-domain.com"
    },
    "provider": "teamcity"
  },
  "owner": "my-bitbucket-project",
  "repo": "my-bitbucket-repository",
  "vcs": {
    "domain": "bitbucket.my-company-domain.com",
    "env": {
      "username": "BITBUCKET_USERNAME",
      "password": "BITBUCKET_PASSWORD"
    },
    "provider": "bitbucket-server"
  }
}

ci.env.buildNumber

A string that provides the environment variable that holds the TeamCity build number on the agent that runs your build. One way to set that variable is with the following in your Build Step:

export TEAMCITY_BUILD_NUMBER="%teamcity.build.id%"

ci.env.pr

A string that provides the environment variable that holds the PR number of the pull request being built (empty when a not a PR build). One way to fill that variable is by including the following in your Build Step:

stripped_branch=\$(echo "%teamcity.build.branch%" | sed -e "s/\/merge//")
re='^[0-9]+$'
if [[ \$stripped_branch =~ \$re ]]
then
    export TEAMCITY_PULL_REQUEST="\$stripped_branch"
else
    export TEAMCITY_PULL_REQUEST="false"
fi

ci.gitUser

You can configure the email and name that will be used by the git user for the commit that bumps the version in package.json and prepends content to CHANGELOG.md This setting can be used even if you're using the travis provider (see below)

ci.provider

Here you configure what CI system you use, the only currently supported options are travis (the default), or teamcity

owner

The Bitbucket project where your repository resides

repo

The name of your Bitbucket repository

vcs.domain

The domain of your Bitbucket Server installation

vcs.env.username and vcs.env.password

Strings that provide the environment variables which hold the credentials for a user with write permissions on the repository in question.

vcs.provider

Here you configure what VCS system you use, the only currently supported options are github (the default), or bitbucket-server

@@ -66,10 +66,7 @@ class Bumper {
*/
getOpenPrScope () {
const vcs = this.vcs
return utils.getSha(this.config, vcs)
.then((sha) => {
return vcs.getOpenPrForSha(sha)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was able to factor out both the getSha() and the getOpenPrForSha() methods because the CI environments we support both have access to the pull request number, which is a much more efficient way to get the PR from the API than by looking for all PRs that match a sha hash.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7b5e621 on job13er:add-bitbucket-server into * on ciena-blueplanet:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 70aa4b7 on job13er:add-bitbucket-server into * on ciena-blueplanet:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling cc8bd7d on job13er:add-bitbucket-server into * on ciena-blueplanet:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e6c0bb7 on job13er:add-bitbucket-server into * on ciena-blueplanet:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7071f42 on job13er:add-bitbucket-server into * on ciena-blueplanet:master*.

This #minor# change adds bitbucket server API support.
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 02c80f7 on job13er:add-bitbucket-server into * on ciena-blueplanet:master*.

})
.then(() => {
return this.ci.push(this.vcs)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be reduced to:

    return this._getMergedPrInfo()
      .then((info) => {
        return this._bumpVersion(info, 'package.json')
      })
      .then((info) => {
        return this._prependChangelog(info, 'CHANGELOG.md')
      })
      .then(this._commitChanges.bind(this))
      .then(this._createTag.bind(this))
      .then(this.ci.push.bind(this, this.vcs))

and if you change the order of the arguments on _bumpVersion() and _prependChangelog() it could be reduced further to:

    return this._getMergedPrInfo()
      .then(this._bumpVersion.bind(this, 'package.json'))
      .then(this._prependChangelog.bind(this, 'CHANGELOG.md'))
      .then(this._commitChanges.bind(this))
      .then(this._createTag.bind(this))
      .then(this.ci.push.bind(this, this.vcs))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but to me, that's less readable.

@sandersky
Copy link
Contributor

sandersky commented May 19, 2016

👍

Approved with PullApprove

@job13er job13er merged commit 6ccc034 into ciena-blueplanet:master May 19, 2016
@job13er job13er deleted the add-bitbucket-server branch May 19, 2016 15:13
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