Skip to content

Commit

Permalink
fix(core): allow git URLs not ending in .git
Browse files Browse the repository at this point in the history
  • Loading branch information
thsig committed Jan 21, 2020
1 parent c308f46 commit 542e205
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
5 changes: 0 additions & 5 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion garden-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"indent-string": "^4.0.0",
"inquirer": "^7.0.1",
"ip": "^1.1.5",
"is-git-url": "^1.0.0",
"is-glob": "^4.0.1",
"is-url": "^1.2.4",
"js-yaml": "^3.13.1",
Expand Down
11 changes: 3 additions & 8 deletions garden-service/src/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Joi from "@hapi/joi"
import { splitLast } from "../util/util"
import isGitUrl from "is-git-url"
import { deline, dedent } from "../util/string"

export type Primitive = string | number | boolean | null
Expand Down Expand Up @@ -209,16 +208,11 @@ joi = joi.extend({
requireHash: "{{#label}} must specify a branch/tag hash",
},
validate(value: string, { error }) {
// Make sure it's a string
const baseSchema = Joi.string()
const baseSchema = joi.string().regex(gitUrlRegex)
const result = baseSchema.validate(value)

if (result.error) {
return { value, errors: result.error }
}

if (!isGitUrl(value)) {
return { value, errors: error("gitUrl") }
return { value, errors: error("base") }
}

return { value }
Expand Down Expand Up @@ -259,6 +253,7 @@ export const absolutePathRegex = /^\/.*/ // Note: Only checks for the leading sl
export const identifierRegex = /^(?![0-9]+$)(?!.*-$)(?!-)[a-z0-9-]{1,63}$/
export const userIdentifierRegex = /^(?!garden)(?=.{1,63}$)[a-z][a-z0-9]*(-[a-z0-9]+)*$/
export const envVarRegex = /^(?!garden)[a-z_][a-z0-9_\.]*$/i
export const gitUrlRegex = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\/?|\#[-\d\w._\/]+?)$/

export const joiIdentifierDescription =
"valid RFC1035/RFC1123 (DNS) label (may contain lowercase letters, numbers and dashes, must start with a letter, " +
Expand Down
14 changes: 14 additions & 0 deletions garden-service/test/unit/src/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ describe("joiRepositoryUrl", () => {
expect(result.error).to.be.undefined
})

it("should accept a git:// URL not ending in .git", () => {
const url = "git://github.com/garden-io/garden-example-remote-sources-web-services#my-tag"
const schema = joiRepositoryUrl()
const result = schema.validate(url)
expect(result.error).to.be.undefined
})

it("should accept an HTTPS Git URL", () => {
const url = "https://github.com/garden-io/garden-example-remote-sources-web-services.git#my-tag"
const schema = joiRepositoryUrl()
Expand Down Expand Up @@ -318,6 +325,13 @@ describe("joiRepositoryUrl", () => {
expect(result.error).to.exist
})

it("should reject values missing a schema", () => {
const url = "garden-io/garden-example-remote-sources-web-services.git#my-tag"
const schema = joiRepositoryUrl()
const result = schema.validate(url)
expect(result.error).to.exist
})

it("should require a branch/tag name", () => {
const url = "https://github.com/garden-io/garden-example-remote-sources-web-services.git"
const schema = joiRepositoryUrl()
Expand Down

0 comments on commit 542e205

Please sign in to comment.