Comparing version 1.0.0 to 1.1.0
@@ -6,17 +6,15 @@ 'use strict'; | ||
const projectSearch = jest.fn(); | ||
const projectSearchAll = jest.fn(); | ||
const issueSearch = jest.fn(); | ||
const groupSearch = jest.fn(); | ||
jest.spyOn(require('gitlab'), 'Gitlab').mockImplementation(() => ({ | ||
jest.spyOn(require('@gitbeaker/node'), 'Gitlab').mockImplementation(() => ({ | ||
Projects: { | ||
search: projectSearch, | ||
all: projectSearchAll | ||
all: projectSearch, | ||
}, | ||
Issues: { | ||
all: issueSearch | ||
all: issueSearch, | ||
}, | ||
Groups: { | ||
search: groupSearch | ||
} | ||
all: groupSearch, | ||
}, | ||
})); | ||
@@ -40,3 +38,2 @@ | ||
projectSearch.mockClear(); | ||
projectSearchAll.mockClear(); | ||
issueSearch.mockClear(); | ||
@@ -54,3 +51,3 @@ groupSearch.mockClear(); | ||
const beginsWith = input => | ||
const beginsWith = (input) => | ||
new RegExp(`^${input.toString().replace(/[()[\]\\/]/gim, '\\$&')}`); | ||
@@ -60,3 +57,2 @@ | ||
projectSearch, | ||
projectSearchAll, | ||
issueSearch, | ||
@@ -72,3 +68,3 @@ groupSearch, | ||
writeFile, | ||
beginsWith | ||
beginsWith, | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
projectSearch, | ||
projectSearchAll, | ||
issueSearch, | ||
@@ -11,3 +10,3 @@ groupSearch, | ||
consoleError, | ||
beginsWith | ||
beginsWith, | ||
} = require('../Harness'); | ||
@@ -17,3 +16,3 @@ const ERRORS = require('../../src/ERRORS'); | ||
describe.only('GitLab implementation', () => { | ||
describe('GitLab implementation', () => { | ||
describe('Core', () => { | ||
@@ -53,3 +52,3 @@ test('will exit and print errors if no settings exists', async () => { | ||
new GitLab('https://testweb.gitlab.jp:1234/team/foo', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -104,3 +103,3 @@ | ||
'/gitlab-com/support-forum/issues', | ||
'https://gitlab.com' | ||
'https://gitlab.com', | ||
]); | ||
@@ -115,3 +114,3 @@ expect(consoleError).toHaveBeenCalledTimes(0); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -128,12 +127,13 @@ await git.authenticate(); | ||
test('will return no errors and the api context if the user has access to the project', async () => { | ||
projectSearchAll.mockResolvedValueOnce([]); | ||
projectSearch.mockResolvedValueOnce([ | ||
{ | ||
id: 114, | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum' | ||
} | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum', | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]); | ||
groupSearch.mockResolvedValueOnce([]); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -154,11 +154,13 @@ const { api, projectId, groupId } = await git.authenticate(); | ||
test('will return no errors and the api context if the user has access to the group', async () => { | ||
projectSearch.mockResolvedValueOnce([]); | ||
groupSearch.mockResolvedValueOnce([ | ||
{ | ||
id: 123, | ||
web_url: 'https://gitlab.com/groups/gitlab-com' | ||
} | ||
web_url: 'https://gitlab.com/groups/gitlab-com', | ||
full_path: 'gitlab-com', | ||
}, | ||
]); | ||
const git = new GitLab('https://gitlab.com/groups/gitlab-com', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -181,12 +183,13 @@ const { api, projectId, groupId } = await git.authenticate(); | ||
test('will not return any issues if the user does not have access to the project', async () => { | ||
projectSearchAll.mockResolvedValueOnce([]); | ||
projectSearch.mockResolvedValueOnce([ | ||
{ | ||
id: 114, | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum' | ||
} | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum', | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]); | ||
groupSearch.mockResolvedValueOnce([]); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -204,12 +207,13 @@ const { api } = await git.authenticate(); | ||
test('will not return any issues if the user does not have access to the group', async () => { | ||
projectSearchAll.mockResolvedValueOnce([]); | ||
projectSearch.mockResolvedValueOnce([ | ||
{ | ||
id: 114, | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum' | ||
} | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum', | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]); | ||
groupSearch.mockResolvedValueOnce([]); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -230,16 +234,17 @@ const { api } = await git.authenticate(); | ||
issue: 'foo issue', | ||
test: 'pass' | ||
} | ||
test: 'pass', | ||
}, | ||
]; | ||
projectSearchAll.mockResolvedValueOnce([]); | ||
projectSearch.mockResolvedValueOnce([ | ||
projectSearch.mockResolvedValue([ | ||
{ | ||
id: 114, | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum' | ||
} | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum', | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]); | ||
issueSearch.mockResolvedValueOnce(MOCK_ISSUES); | ||
groupSearch.mockResolvedValue([]); | ||
issueSearch.mockResolvedValue(MOCK_ISSUES); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -265,15 +270,17 @@ const { api, projectId, groupId } = await git.authenticate(); | ||
issue: 'foo issue', | ||
test: 'pass' | ||
} | ||
test: 'pass', | ||
}, | ||
]; | ||
groupSearch.mockResolvedValueOnce([ | ||
projectSearch.mockResolvedValue([]); | ||
groupSearch.mockResolvedValue([ | ||
{ | ||
id: 123, | ||
web_url: 'https://gitlab.com/groups/gitlab-com' | ||
} | ||
web_url: 'https://gitlab.com/groups/gitlab-com', | ||
full_path: 'gitlab-com', | ||
}, | ||
]); | ||
issueSearch.mockResolvedValueOnce(MOCK_ISSUES); | ||
issueSearch.mockResolvedValue(MOCK_ISSUES); | ||
const git = new GitLab('https://gitlab.com/groups/gitlab-com', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -300,17 +307,17 @@ const { api, projectId, groupId } = await git.authenticate(); | ||
web_url: 'https://gitlab.com/gitlab-com/support-forum', | ||
path_with_namespace: 'foo/bar/baz' | ||
} | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]; | ||
projectSearchAll.mockReturnValue(projects); | ||
projectSearch.mockReturnValue(projects); | ||
issueSearch.mockReturnValue([ | ||
projectSearch.mockResolvedValue(projects); | ||
groupSearch.mockResolvedValue([]); | ||
issueSearch.mockResolvedValue([ | ||
{ | ||
project_id: 114, | ||
issue: 'foo issue', | ||
test: 'pass' | ||
} | ||
test: 'pass', | ||
}, | ||
]); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -334,4 +341,4 @@ const { api, projectId, groupId } = await git.authenticate(); | ||
project_id: 114, | ||
project_name: 'foo/bar/baz' | ||
} | ||
project_name: 'gitlab-com/support-forum', | ||
}, | ||
]); | ||
@@ -344,3 +351,3 @@ }); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -361,3 +368,3 @@ git.addProjectNames(); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -378,3 +385,3 @@ git.addProjectNames({}); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -395,3 +402,3 @@ git.addProjectNames({}, {}); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -412,3 +419,3 @@ git.addProjectNames({}, null); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -429,3 +436,3 @@ git.addProjectNames({}, ''); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -448,4 +455,4 @@ git.addProjectNames({}, 1); | ||
id: 1, | ||
path_with_namespace: 'test/me' | ||
} | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]; | ||
@@ -455,9 +462,10 @@ const issues = [ | ||
project_id: 1, | ||
issue: 'anything' | ||
} | ||
issue: 'anything', | ||
}, | ||
]; | ||
projectSearchAll.mockReturnValue(projects); | ||
projectSearch.mockReturnValue(projects); | ||
groupSearch.mockReturnValue([]); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -475,4 +483,4 @@ const { api } = await git.authenticate(); | ||
issue: 'anything', | ||
project_name: 'test/me' | ||
} | ||
project_name: 'gitlab-com/support-forum', | ||
}, | ||
]); | ||
@@ -485,4 +493,4 @@ }); | ||
id: 2, | ||
path_with_namespace: 'test/me' | ||
} | ||
path_with_namespace: 'gitlab-com/support-forum', | ||
}, | ||
]; | ||
@@ -492,9 +500,10 @@ const issues = [ | ||
project_id: 1, | ||
issue: 'anything' | ||
} | ||
issue: 'anything', | ||
}, | ||
]; | ||
projectSearchAll.mockReturnValue(projects); | ||
projectSearch.mockReturnValue(projects); | ||
groupSearch.mockReturnValue([]); | ||
const git = new GitLab('https://gitlab.com/gitlab-com/support-forum', { | ||
auth: 'token_secret' | ||
auth: 'token_secret', | ||
}); | ||
@@ -512,4 +521,4 @@ const { api } = await git.authenticate(); | ||
issue: 'anything', | ||
project_name: '' | ||
} | ||
project_name: '', | ||
}, | ||
]); | ||
@@ -516,0 +525,0 @@ }); |
@@ -9,4 +9,10 @@ # Changelog | ||
## [1.1.0 - 12/04/2020] | ||
- Replacing gitlab dep with the latest version | ||
- Fixing .env parsing issues | ||
- Adding .prettierrc | ||
## [1.0.0 - 01/07/2020] | ||
- Initial release |
module.exports = { | ||
testRegex: '(__tests__.*|(.|/)).(test|spec).[jt]sx?$' | ||
testRegex: '(__tests__.*|(.|/)).(test|spec).[jt]sx?$', | ||
verbose: true, | ||
automock: false, | ||
}; |
{ | ||
"name": "isren", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "isren - ISsue Rendering ENgine", | ||
"main": "./src/index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"test": "NODE_ENV=test jest ", | ||
"coverage": "jest --coverage", | ||
"format": "prettier '**/**.js' --single-quote --write", | ||
"format": "prettier '**/**.js' --write", | ||
"start": "node ./src/CLI.js", | ||
@@ -30,11 +30,11 @@ "lint": "eslint '**/**.js'" | ||
"eslint-plugin-standard": "^4.0.0", | ||
"jest": "^24.8.0", | ||
"jest": "^26.6.3", | ||
"prettier": "^1.19.1" | ||
}, | ||
"dependencies": { | ||
"@gitbeaker/node": "^25.6.0", | ||
"commander": "^4.0.1", | ||
"csv-stringify": "^5.3.0", | ||
"dotenv": "^8.0.0", | ||
"gitlab": "^11.5.1" | ||
"dotenv": "^8.0.0" | ||
} | ||
} |
#!/usr/bin/env node | ||
require('dotenv').config(); | ||
const path = require('path'); | ||
require('dotenv').config({ path: path.resolve(__dirname, '../', '.env') }); | ||
const program = require('commander'); | ||
@@ -4,0 +5,0 @@ const index = require('./index'); |
@@ -7,2 +7,3 @@ { | ||
"MISSING_PROJECT": "Project not found!", | ||
"DUPLICATE_PROJECT_GROUP_NAME": "A project and group with the same name exist!", | ||
"MISSING_ISSUES": "Issue listing failed!", | ||
@@ -9,0 +10,0 @@ "NYI_IS_IMPLEMENTATION": "isImplementation() is not defined for", |
'use strict'; | ||
const { URL } = require('url'); | ||
const { Gitlab: Git } = require('gitlab'); | ||
const { Gitlab: Git } = require('@gitbeaker/node'); | ||
const Implementation = require('./index'); | ||
@@ -62,35 +62,32 @@ const Logger = require('../Logger'); | ||
token: this.auth, | ||
host | ||
host, | ||
rejectUnauthorized: !this.insecure, | ||
}); | ||
const [, groups, group] = path.split('/'); | ||
// Determine what type of url we have. | ||
let projectName, groupName; | ||
if (/groups/gi.test(groups)) { | ||
groupName = group; | ||
} else { | ||
groupName = groups; | ||
projectName = group; | ||
} | ||
try { | ||
const GROUPS = await api.Groups.all(); | ||
const PROJECTS = await api.Projects.all(); | ||
const PATH = path.slice(1).replace(/^(groups\/)/gi, ''); | ||
const group = GROUPS.find((g) => g.full_path === PATH); | ||
const project = PROJECTS.find((p) => p.path_with_namespace === PATH); | ||
try { | ||
if (projectName !== undefined) { | ||
const [currentProject] = ( | ||
await api.Projects.search(projectName) | ||
).filter(projectInfo => projectInfo.web_url.includes(path)); | ||
const projectId = currentProject.id; | ||
Logger.debug( | ||
`path=${PATH}, groups count=${GROUPS.length}, project count=${ | ||
PROJECTS.length | ||
}, group=${!!group}, project=${!!project}` | ||
); | ||
if (!group && !project) return Logger.fatal(ERRORS.MISSING_PROJECT); | ||
if (group && project) | ||
return Logger.fatal(ERRORS.DUPLICATE_PROJECT_GROUP_NAME); | ||
if (group) { | ||
console.log( | ||
`Authentication success! Current project is ${path}(#${projectId})` | ||
`Authentication success! Current group is ${group.full_path}(#${group.id})` | ||
); | ||
return { api, projectId }; | ||
return { api, groupId: group.id }; | ||
} | ||
const [currentGroup] = ( | ||
await api.Groups.search(groupName) | ||
).filter(groupInfo => groupInfo.web_url.includes(path)); | ||
const groupId = currentGroup.id; | ||
console.log( | ||
`Authentication success! Current group is ${path}(#${groupId})` | ||
`Authentication success! Current project is ${project.path_with_namespace}(#${project.id})` | ||
); | ||
return { api, groupId }; | ||
return { api, projectId: project.id }; | ||
} catch (e) { | ||
@@ -121,3 +118,3 @@ if (e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') { | ||
projectId, | ||
...options | ||
...options, | ||
}); | ||
@@ -128,3 +125,3 @@ } | ||
groupId, | ||
...options | ||
...options, | ||
}); | ||
@@ -168,3 +165,3 @@ } | ||
return issues.map(issue => { | ||
return issues.map((issue) => { | ||
issue.project_name = projects[issue.project_id] || ''; | ||
@@ -171,0 +168,0 @@ return issue; |
@@ -17,2 +17,3 @@ 'use strict'; | ||
this.auth = this.cmd.auth || AUTH; | ||
this.insecure = false; | ||
@@ -30,6 +31,4 @@ // Output type normalization from string to array of strings. | ||
// Note: The `rejectUnauthorized` parameter is not working, this is a | ||
// temporary work-around | ||
if (this.cmd.insecure) { | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; | ||
this.insecure = true; | ||
} | ||
@@ -36,0 +35,0 @@ |
@@ -10,2 +10,13 @@ 'use strict'; | ||
/** | ||
* Log a debug message. | ||
* | ||
* @param {String|Array} message | ||
* The debug message to log | ||
*/ | ||
debug(...message) { | ||
if (!this.debugMode) return; | ||
console.log(...message); | ||
}, | ||
/** | ||
* Log an error. | ||
@@ -12,0 +23,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
169496
41
1567
10
+ Added@gitbeaker/node@^25.6.0
+ Added@gitbeaker/core@25.6.0(transitive)
+ Added@gitbeaker/node@25.6.0(transitive)
+ Added@gitbeaker/requester-utils@25.6.0(transitive)
+ Added@sindresorhus/is@4.6.0(transitive)
+ Added@szmarczak/http-timer@4.0.6(transitive)
+ Added@types/cacheable-request@6.0.3(transitive)
+ Added@types/http-cache-semantics@4.0.4(transitive)
+ Added@types/keyv@3.1.4(transitive)
+ Added@types/node@22.9.3(transitive)
+ Added@types/responselike@1.0.3(transitive)
+ Addedcacheable-lookup@5.0.4(transitive)
+ Addedcacheable-request@7.0.4(transitive)
+ Addedclone-response@1.0.3(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddefer-to-connect@2.0.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedget-stream@5.2.0(transitive)
+ Addedgot@11.8.6(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedhttp2-wrapper@1.0.3(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlowercase-keys@2.0.0(transitive)
+ Addedmimic-response@1.0.13.1.0(transitive)
+ Addednormalize-url@6.1.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-cancelable@2.1.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedresponselike@2.0.1(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedgitlab@^11.5.1
- Removedabort-controller@3.0.0(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@3.2.14.3.0(transitive)
- Removedchalk@2.4.23.0.0(transitive)
- Removedcli-cursor@3.1.0(transitive)
- Removedcli-spinners@2.9.2(transitive)
- Removedclone@1.0.4(transitive)
- Removedcolor-convert@1.9.32.0.1(transitive)
- Removedcolor-name@1.1.31.1.4(transitive)
- Removeddefaults@1.0.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedevent-target-shim@5.0.1(transitive)
- Removedgitlab@11.6.1(transitive)
- Removedhas-flag@3.0.04.0.0(transitive)
- Removedis-interactive@1.0.0(transitive)
- Removedky@0.16.2(transitive)
- Removedky-universal@0.3.0(transitive)
- Removedlog-symbols@3.0.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removedmute-stream@0.0.8(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedonetime@5.1.2(transitive)
- Removedora@4.1.1(transitive)
- Removedrestore-cursor@3.1.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@5.5.07.2.0(transitive)
- Removedsywac@1.3.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwcwidth@1.0.1(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)