-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle greenkeeper.json changes
- Loading branch information
Showing
8 changed files
with
1,751 additions
and
102 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
couchdb/repositories/_design/branch_by_group/views/branch_by_group/map.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function (doc) { | ||
if (doc.type !== 'branch' || doc.referenceDeleted) return | ||
if (doc.head && typeof doc.head === 'string') { | ||
var branchName = doc.head.split('/') | ||
if (branchName[1]) { | ||
emit([doc.repositoryId, branchName[1]]) | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,26 @@ | ||
const _ = require('lodash') | ||
const semver = require('semver') | ||
|
||
const dbs = require('../lib/dbs') | ||
const updatedAt = require('../lib/updated-at') | ||
const githubQueue = require('./github-queue') | ||
|
||
module.exports = async function ( | ||
{ installationId, fullName, repositoryId }, | ||
{ change, after, dependency, dependencyType, groupName } | ||
branch | ||
) { | ||
if (change !== 'removed' && !semver.validRange(after)) return | ||
const { repositories } = await dbs() | ||
|
||
const [owner, repo] = fullName.split('/') | ||
console.log('branch to be deleted', branch) | ||
if (!branch) return | ||
let referenceDeleted = false | ||
try { | ||
// TODO: check if modified | ||
await githubQueue(installationId).write(github => github.gitdata.deleteReference({ | ||
owner, | ||
repo, | ||
ref: `heads/${branch.head}` | ||
})) | ||
referenceDeleted = true | ||
} catch (e) {} | ||
updatedAt(Object.assign(branch, { referenceDeleted })) | ||
|
||
// TODO: this would return multiple branch docs, possibly for irrelevant groups, | ||
// or if a group is specified, for irrelevant root level package.json | ||
const branches = _.map( | ||
(await repositories.query('branch_by_dependency', { | ||
key: [repositoryId, dependency, dependencyType], | ||
include_docs: true | ||
})).rows, | ||
'doc' | ||
) | ||
|
||
const branchDocs = await Promise.all( | ||
_(branches) | ||
.filter( | ||
branch => | ||
// include branch if dependency was removed | ||
change === 'removed' || | ||
// include branch if update version satisfies branch version (branch is outdated) | ||
semver.satisfies(branch.version, after) || | ||
// include branch if is not satisfied, but later (eg. update is an out of range major update) | ||
semver.ltr(branch.version, after) | ||
) | ||
.filter( | ||
branch => { | ||
// if groupName is passed in, only include branches of that group | ||
// branch.head = 'greenkeeper/${groupName}/${dependency}' | ||
if (groupName) { | ||
return branch.head.includes(`greenkeeper/${groupName}/`) | ||
} else { | ||
// If there's no groupName, only return branches that don’t belong to groups | ||
return branch.head.includes(`greenkeeper/${dependency}`) | ||
} | ||
}) | ||
.map(async branch => { | ||
let referenceDeleted = false | ||
try { | ||
// TODO: check if modified | ||
await githubQueue(installationId).write(github => github.gitdata.deleteReference({ | ||
owner, | ||
repo, | ||
ref: `heads/${branch.head}` | ||
})) | ||
referenceDeleted = true | ||
} catch (e) {} | ||
return updatedAt(Object.assign(branch, { referenceDeleted })) | ||
}) | ||
.value() | ||
) | ||
|
||
return repositories.bulkDocs(branchDocs) | ||
return repositories.bulkDocs([branch]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const _ = require('lodash') | ||
|
||
module.exports = function (oldFile, newFile) { | ||
const changes = {added: [], removed: [], modified: []} | ||
if (!newFile || !oldFile) return changes | ||
// new groups added | ||
_.set(changes, 'added', _.difference(_.keys(newFile.groups), _.keys(oldFile.groups))) | ||
// groups removed | ||
_.set(changes, 'removed', _.difference(_.keys(oldFile.groups), _.keys(newFile.groups))) | ||
// groups modified | ||
_.set(changes, 'modified', _.compact(_.map(oldFile.groups, (group, key) => { | ||
if (newFile.groups[key] && !_.isEqual(group.packages, newFile.groups[key].packages)) return key | ||
}))) | ||
|
||
return changes | ||
} |
Oops, something went wrong.