Skip to content

Commit 71f6278

Browse files
authored
fix: usernames can have brackets (#61)
* fix: ensure usernames are valid * fix: ensure usernames are valid * pr: lint * pr: add-add
1 parent 9ef0271 commit 71f6278

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"prettier": "^1.15.3",
4343
"serverless": "^1.35.1",
4444
"serverless-offline": "^4.0.0",
45+
"shelljs": "^0.8.3",
4546
"smee-client": "^1.0.2"
4647
},
4748
"nodemonConfig": {

src/processIssueComment.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const {
1313
ResourceNotFoundError,
1414
} = require('./utils/errors')
1515

16+
const getSafeRef = require('./utils/git/getSafeRef')
17+
1618
async function processAddContributor({
1719
context,
1820
commentReply,
@@ -49,13 +51,14 @@ async function processAddContributor({
4951
originalSha: optionsConfig.getOriginalSha(),
5052
}
5153

54+
const safeWho = getSafeRef(who)
5255
const pullRequestURL = await repository.createPullRequestFromFiles({
5356
title: `docs: add ${who} as a contributor`,
5457
body: `Adds @${who} as a contributor for ${contributions.join(
5558
', ',
5659
)}.\n\nThis was requested by ${commentReply.replyingToWho()} [in this comment](${commentReply.replyingToWhere()})`,
5760
filesByPath: filesByPathToUpdate,
58-
branchName: `all-contributors/add-${who}`,
61+
branchName: `all-contributors/add-${safeWho}`,
5962
defaultBranch,
6063
})
6164

src/utils/git/getSafeRef.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable no-useless-escape */
2+
3+
function getSafeRef(ref) {
4+
// Replace fullstops
5+
// ~, ^ or : ? * [
6+
// /
7+
// remove @ sybmobls
8+
// remove backslash
9+
const safeRef = ref.replace(/[\.\[\~\^\:\?\*\@\/\\]/gi, '-')
10+
return safeRef
11+
}
12+
13+
module.exports = getSafeRef

test/utils/git/getSafeRef.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { exec } = require('shelljs')
2+
3+
const getSafeRef = require('../../../src/utils/git/getSafeRef')
4+
5+
const testIsBranchSafe = function(branchNameIn, branchNameOut) {
6+
const safeRef = getSafeRef(branchNameIn)
7+
expect(safeRef).toEqual(branchNameOut)
8+
const checkFormat = exec(`git check-ref-format --branch ${safeRef}`)
9+
if (checkFormat.code !== 0) {
10+
throw new Error(`${safeRef} is not safe from git`)
11+
}
12+
}
13+
14+
describe('getSafeRef', () => {
15+
test('Converts invalid chars to make ref safe', () => {
16+
testIsBranchSafe('all-contributors[bot]', 'all-contributors-bot]')
17+
testIsBranchSafe('branch.lol..', 'branch-lol--')
18+
testIsBranchSafe('branch^yep', 'branch-yep')
19+
testIsBranchSafe('branch/yep', 'branch-yep')
20+
testIsBranchSafe('branch\\yep', 'branch-yep')
21+
})
22+
})

yarn.lock

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ align-text@^0.1.1, align-text@^0.1.3:
280280
all-contributors-cli@^5.10.1:
281281
version "5.10.1"
282282
resolved "https://registry.yarnpkg.com/all-contributors-cli/-/all-contributors-cli-5.10.1.tgz#1bb5cfcfcd60ec5e07a1c3d23c1c29c94ba14138"
283-
integrity sha512-Vpvdiliiw6YEjSrEun3hN8FR80nwOMgvrThGsNd1RY6DhpPuhLLp2MTPrMSmPuaUBZIcD3DxtHqvbK8HQ7zEwg==
284283
dependencies:
285284
async "^2.0.0-rc.1"
286285
chalk "^2.3.0"
@@ -936,7 +935,6 @@ cache-manager@^2.4.0:
936935
937936
version "4.0.2"
938937
resolved "https://registry.yarnpkg.com/call/-/call-4.0.2.tgz#df76f5f51ee8dd48b856ac8400f7e69e6d7399c4"
939-
integrity sha1-33b19R7o3Ui4VqyEAPfmnm1zmcQ=
940938
dependencies:
941939
boom "5.x.x"
942940
hoek "4.x.x"
@@ -2366,7 +2364,6 @@ growly@^1.3.0:
23662364
h2o2@^6.1.0:
23672365
version "6.1.0"
23682366
resolved "https://registry.yarnpkg.com/h2o2/-/h2o2-6.1.0.tgz#2b2e7fcca0e3665c9497645e3203af99ed9033f1"
2369-
integrity sha1-Ky5/zKDjZlyUl2ReMgOvme2QM/E=
23702367
dependencies:
23712368
boom "5.x.x"
23722369
hoek "4.x.x"
@@ -2400,7 +2397,6 @@ hapi-cors-headers@^1.0.3:
24002397
hapi@^16.7.0:
24012398
version "16.7.0"
24022399
resolved "https://registry.yarnpkg.com/hapi/-/hapi-16.7.0.tgz#3bb39517971df81e8198ec04751455e8b6cb0871"
2403-
integrity sha512-UeMX1LMWmHEIgMlwZGK/3lhI7X0VRvOioVply0Y9qF+/O5woGdQzNB8ZmDnLOBjnB6bdWWHyo5DEamuCsE1vmg==
24042400
dependencies:
24052401
accept "2.x.x"
24062402
ammo "2.x.x"
@@ -2693,6 +2689,10 @@ inquirer@^6.1.0:
26932689
strip-ansi "^5.0.0"
26942690
through "^2.3.6"
26952691

2692+
interpret@^1.0.0:
2693+
version "1.2.0"
2694+
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.2.0.tgz#d5061a6224be58e8083985f5014d844359576296"
2695+
26962696
invariant@^2.2.2, invariant@^2.2.4:
26972697
version "2.2.4"
26982698
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@@ -2977,7 +2977,6 @@ [email protected]:
29772977
29782978
version "3.2.0"
29792979
resolved "https://registry.yarnpkg.com/isemail/-/isemail-3.2.0.tgz#59310a021931a9fb06bbb51e155ce0b3f236832c"
2980-
integrity sha512-zKqkK+O+dGqevc93KNsbZ/TqTUFd46MwWjYOoMrjIMZ51eU7DtQG3Wmd9SQQT7i7RVnuTPEiYEWHU3MSbxC1Tg==
29812980
dependencies:
29822981
punycode "2.x.x"
29832982

@@ -3220,7 +3219,6 @@ jest-jasmine2@^23.6.0:
32203219
jest-junit@^6.0.1:
32213220
version "6.0.1"
32223221
resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-6.0.1.tgz#7c24b2aff4ddfce3a8c0e0c84978123c0d4a945a"
3223-
integrity sha512-gMJb8qqyLKTD4pyaU8gjQv6wiudAqEFFt2VFswJ/+swB69WQh5mMn8tezR9B8ukejHjFbq5y9qbYWxi9uZeQZA==
32243222
dependencies:
32253223
jest-config "^23.6.0"
32263224
jest-validate "^23.0.1"
@@ -3397,7 +3395,6 @@ [email protected]:
33973395
33983396
version "11.4.0"
33993397
resolved "https://registry.yarnpkg.com/joi/-/joi-11.4.0.tgz#f674897537b625e9ac3d0b7e1604c828ad913ccb"
3400-
integrity sha512-O7Uw+w/zEWgbL6OcHbyACKSj0PkQeUgmehdoXVSxt92QFCq4+1390Rwh5moI2K/OgC7D8RHRZqHZxT2husMJHA==
34013398
dependencies:
34023399
hoek "4.x.x"
34033400
isemail "3.x.x"
@@ -4517,7 +4514,6 @@ pn@^1.1.0:
45174514
45184515
version "1.3.0"
45194516
resolved "https://registry.yarnpkg.com/podium/-/podium-1.3.0.tgz#3c490f54d16f10f5260cbe98641f1cb733a8851c"
4520-
integrity sha512-ZIujqk1pv8bRZNVxwwwq0BhXilZ2udycQT3Kp8ah3f3TcTmVg7ILJsv/oLf47gRa2qeiP584lNq+pfvS9U3aow==
45214517
dependencies:
45224518
hoek "4.x.x"
45234519
items "2.x.x"
@@ -4767,6 +4763,12 @@ realpath-native@^1.0.0:
47674763
dependencies:
47684764
util.promisify "^1.0.0"
47694765

4766+
rechoir@^0.6.2:
4767+
version "0.6.2"
4768+
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
4769+
dependencies:
4770+
resolve "^1.1.6"
4771+
47704772
regenerator-runtime@^0.10.5:
47714773
version "0.10.5"
47724774
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"
@@ -4900,7 +4902,7 @@ [email protected]:
49004902
version "1.1.7"
49014903
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
49024904

4903-
resolve@^1.3.2, resolve@^1.4.0:
4905+
resolve@^1.1.6, resolve@^1.3.2, resolve@^1.4.0:
49044906
version "1.9.0"
49054907
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06"
49064908
dependencies:
@@ -5063,7 +5065,6 @@ [email protected]:
50635065
serverless-offline@^4.0.0:
50645066
version "4.0.0"
50655067
resolved "https://registry.yarnpkg.com/serverless-offline/-/serverless-offline-4.0.0.tgz#3ba9fe467ed6b7a0e4661160b2d7929bd5ca03df"
5066-
integrity sha512-KG8wzrMZyOdI3MtDRahZq0u1O+MCHTRQVugitTo5wfLJKCqWSdtSXy6lW18NLMHoPYfCf+5hdB3vT/nCK6zqug==
50675068
dependencies:
50685069
"@babel/core" "^7.0.0"
50695070
"@babel/register" "^7.0.0"
@@ -5157,6 +5158,14 @@ shebang-regex@^1.0.0:
51575158
version "1.0.0"
51585159
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
51595160

5161+
shelljs@^0.8.3:
5162+
version "0.8.3"
5163+
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097"
5164+
dependencies:
5165+
glob "^7.0.0"
5166+
interpret "^1.0.0"
5167+
rechoir "^0.6.2"
5168+
51605169
shellwords@^0.1.1:
51615170
version "0.1.1"
51625171
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
@@ -5228,7 +5237,6 @@ snapdragon@^0.8.1:
52285237
52295238
version "1.0.1"
52305239
resolved "https://registry.yarnpkg.com/somever/-/somever-1.0.1.tgz#28a5c7de0d55f781af52fbce9960db1b84ce206e"
5231-
integrity sha512-PCDMBcega4n7wuBUKmkiXidF3cOwtHHGg2qJYl0Rkw7StZqORoCgqce7HUuWNta/NAiQhwLDezNnTANxEWPCGA==
52325240
dependencies:
52335241
hoek "4.x.x"
52345242

@@ -5348,7 +5356,6 @@ stack-utils@^1.0.1:
53485356
53495357
version "5.0.3"
53505358
resolved "https://registry.yarnpkg.com/statehood/-/statehood-5.0.3.tgz#c07a75620db5379b60d2edd47f538002a8ac7dd6"
5351-
integrity sha512-YrPrCt10t3ImH/JMO5szSwX7sCm8HoqVl3VFLOa9EZ1g/qJx/ZmMhN+2uzPPB/vaU6hpkJpXxcBWsgIkkG+MXA==
53525359
dependencies:
53535360
boom "5.x.x"
53545361
cryptiles "3.x.x"
@@ -5455,7 +5462,6 @@ strip-outer@^1.0.0:
54555462
54565463
version "5.0.0"
54575464
resolved "https://registry.yarnpkg.com/subtext/-/subtext-5.0.0.tgz#9c3f083018bb1586b167ad8cfd87083f5ccdfe0f"
5458-
integrity sha512-2nXG1G1V+K64Z20cQII7k0s38J2DSycMXBLMAk9RXUFG0uAkAbLSVoa88croX9VhTdBCJbLAe9g6LmzKwpJhhQ==
54595465
dependencies:
54605466
boom "5.x.x"
54615467
content "3.x.x"

0 commit comments

Comments
 (0)