Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
feat: split repo automatically into org and project, close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 23, 2017
1 parent edafa0a commit f4da7a2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/providers/buildkite.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ _ = require("lodash")
Promise = require("bluebird")
providerApi = require("./buildkite-api")
debug = require("debug")("bumper")
parse = require('parse-github-repo-url')
la = require("lazy-ass")
check = require("check-more-types")

api =
configure: (options={}) ->
api = providerApi.create(options.buildkiteToken)

return {
updateProjectEnv: (organization, project, variables) ->
debug("updating Buildkite variables for", organization, project)
if check.unemptyString(organization) and _.isPlainObject(project)
# user probably passed just repo + variables
debug("extracting org and project from", organization)
variables = project
[organization, project] = parse(organization)

debug("updating Buildkite variables for org '%s' project '%s'", organization, project)
debug(variables)
la(check.unemptyString(organization), "missing organization name", organization)
la(check.unemptyString(project), "missing project name", project)
la(_.isPlainObject(variables), "missing variables object", variables)

api.updateEnvironmentVariables(organization, project, variables)

runProject: (organization, project) ->
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test": "NODE_ENV=test mocha",
"watch": "NODE_ENV=test mocha --watch",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";"
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"issues": "git-issues"
},
"repository": {
"type": "git",
Expand All @@ -19,7 +20,9 @@
"releasing",
"versioning"
],
"files": ["lib"],
"files": [
"lib"
],
"author": "Loren Norman <loren@cypress.io>",
"license": "MIT",
"bugs": {
Expand All @@ -34,12 +37,14 @@
"debug": "^3.1.0",
"lazy-ass": "^1.6.0",
"lodash": "^4.17.4",
"parse-github-repo-url": "^1.4.1",
"ramda": "^0.24.1"
},
"devDependencies": {
"@cypress/releaser": "0.1.12",
"chai": "^3.5.0",
"condition-circle": "^1.5.0",
"git-issues": "^1.3.1",
"github-post-release": "^1.13.1",
"mocha": "^3.2.0",
"nock": "^9.0.24",
Expand Down
22 changes: 22 additions & 0 deletions test/buildkite_provider_spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
buildkiteProvider = require("../lib/providers/buildkite")
buildkiteApi = require("../lib/providers/buildkite-api")

describe "Buildkite Provider", ->
beforeEach ->
@api = {
updateEnvironmentVariables: @sandbox.stub().resolves(true)
}
@sandbox.stub(buildkiteApi, 'create').returns(@api)

@provider = buildkiteProvider.configure({
buildkiteToken: 'abc123'
})

it "passes the buildkite token to api creation", ->
expect(buildkiteApi.create).to.be.calledWith("abc123")

it "splits repo URL into organization and project", ->
vars = { life: 42 }
@provider.updateProjectEnv("foo/bar", vars)
.then =>
expect(@api.updateEnvironmentVariables).to.be.calledWith("foo", "bar", vars)

0 comments on commit f4da7a2

Please sign in to comment.