Skip to content

Commit

Permalink
feat:only pass tokens for repo
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkoba authored and Realtin committed Nov 29, 2018
1 parent c5b250b commit b3104db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/create-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,22 @@ module.exports = async (
}
}
*/
let repositoryTokens = ''
let execTokens = ''
try {
repositoryTokens = await tokens.get(installationId)
const repositoryTokens = await tokens.get(installationId)
execTokens = JSON.stringify(repositoryTokens.tokens[repoDoc._id])

const datetime = new Date().toISOString().substr(0, 19).replace(/[^0-9]/g, '')

// write audit log entry to 'tokens-audit' db
// write audit log entry to 'token-audits' db
// log entry type: 'read'
await tokenAudits.put({
_id: `${installationId}:${repoDoc._id}:${datetime}:read`,
keys: Object.keys(repositoryTokens.tokens[repoDoc._id])
})
} catch (e) {}
const { ok, contents } = await getNewLockfile({ packageJson: commit.content, lock: oldLockfileContent, isNpm, repositoryTokens: JSON.stringify(repositoryTokens) })

const { ok, contents } = await getNewLockfile({ packageJson: commit.content, lock: oldLockfileContent, isNpm, repositoryTokens: execTokens })
if (ok) {
// !ok means the old and new lockfile are the same, so we don’t make a commit
log.info(`new lockfile contents for ${lockfilePath} received`)
Expand Down
12 changes: 6 additions & 6 deletions test/lib/__snapshots__/create-branch.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`create branch with lockfiles change one file (package.json) and generat
Object {
"lock": "{\\"devDependencies\\":{\\"jest\\":\\"1.1.1\\"}}",
"packageJson": "{\\"devDependencies\\":{\\"jest\\":\\"1.2.0\\"}}",
"repositoryTokens": "\\"\\"",
"repositoryTokens": "",
"type": "npm",
}
`;
Expand All @@ -13,7 +13,7 @@ exports[`create branch with lockfiles change one file (package.json) and generat
Object {
"lock": "{\\"devDependencies\\":{\\"jest\\":\\"1.1.1\\"}}",
"packageJson": "{\\"devDependencies\\":{\\"jest\\":\\"1.2.0\\"}}",
"repositoryTokens": "{\\"_id\\":\\"123\\",\\"_rev\\":\\"1-596cc8e8ce706384d3156bd581320e82\\",\\"tokens\\":{\\"one-lockfile-with-token\\":{\\"npm\\":\\"12345\\",\\"github\\":\\"54321\\"}}}",
"repositoryTokens": "{\\"npm\\":\\"12345\\",\\"github\\":\\"54321\\"}",
"type": "npm",
}
`;
Expand All @@ -22,7 +22,7 @@ exports[`create branch with lockfiles change two files (package.json, frontend/p
Object {
"lock": "{\\"devDependencies\\":{\\"jest\\":\\"1.1.1\\"}}",
"packageJson": "{\\"devDependencies\\":{\\"jest\\":\\"1.2.0\\"}}",
"repositoryTokens": "\\"\\"",
"repositoryTokens": "",
"type": "npm",
}
`;
Expand All @@ -31,7 +31,7 @@ exports[`create branch with lockfiles change two files (package.json, frontend/p
Object {
"lock": "{\\"devDependencies\\":{\\"jest\\":\\"1.1.1\\"}}",
"packageJson": "{\\"devDependencies\\":{\\"jest\\":\\"1.2.0\\"}}",
"repositoryTokens": "\\"\\"",
"repositoryTokens": "",
"type": "npm",
}
`;
Expand All @@ -40,7 +40,7 @@ exports[`create branch with lockfiles don’t generate the same lockfile multipl
Object {
"lock": "{\\"devDependencies\\":{\\"jest\\":\\"1.1.1\\",\\"west\\":\\"1.1.1\\"}}",
"packageJson": "{\\"devDependencies\\":{\\"jest\\":\\"1.2.0\\",\\"west\\":\\"1.5.0\\"}}",
"repositoryTokens": "\\"\\"",
"repositoryTokens": "",
"type": "npm",
}
`;
Expand All @@ -49,7 +49,7 @@ exports[`create branch with lockfiles handle exec server 500 gracefully 1`] = `
Object {
"lock": "{\\"devDependencies\\":{\\"jest\\":\\"1.1.1\\"}}",
"packageJson": "{\\"devDependencies\\":{\\"jest\\":\\"1.2.0\\"}}",
"repositoryTokens": "\\"\\"",
"repositoryTokens": "",
"type": "npm",
}
`;

0 comments on commit b3104db

Please sign in to comment.