This repository was archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Feature/455 (Github pull integration #455) #524
Open
zmike808
wants to merge
37
commits into
master
Choose a base branch
from
feature/455
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
13f9dd9
Started work on pulling commit data for project repositories
zmike808 8d87fc7
refactored function name to make more sense
zmike808 beb0333
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 4203d62
Removed unused github.py worker
zmike808 cf05306
removed hardcoded github token for security purposes
zmike808 391b739
P.O.C/test example progress...still heavily debugging...
zmike808 3844aef
more debugging...just commiting to try to keep track of this mess...
zmike808 b90cb28
Revert "more debugging...just commiting to try to keep track of this …
zmike808 276f5cc
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 33fba8d
removed api key from github worker (again...)
zmike808 c68570e
removed runThread from github.js worker; don't think it's currently n…
zmike808 459974e
Added GITHUB_WORKER_KEY env variable.\n Removed hard coded github key…
zmike808 155494b
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 a3d0b6b
Github worker now populates commit model with commits! Still a W.I.P.
zmike808 cec9fed
Merge remote-tracking branch 'origin/master' into feature/454
zmike808 07b1ce2
pulling commits from github now works! Currently fixing up commit api…
zmike808 c312e90
fixed github token env variable, now imports correctly
zmike808 2e092c1
finished commit-project DB relationship link; cleaned up github worke…
zmike808 8d7c026
more env variable issues >.<
zmike808 c366a9c
removed un-needed debug statement
zmike808 d11b05e
Commits working for the most part. Just need to figure out async issu…
zmike808 5fc9797
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 728d307
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 e9649b9
removed un-needed console.log
zmike808 4df1f88
started on switching to a different github api wrapper and using prom…
zmike808 2342c04
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 28dd8c5
Completely overhauled github commit retrival & storage; much more str…
zmike808 e2b3f99
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 9764bd8
minor formatting cleanups
zmike808 a88fef9
cleanup & refactor. WIP: adding configuration options for fetching co…
zmike808 aae63ec
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 0365fec
refactored out some un-needed & commented code
zmike808 1fd9457
Merge remote-tracking branch 'origin/master' into feature/455
zmike808 3faa629
fixed find project query
zmike808 aacba9a
fixed showProjectCommits query again
zmike808 fd3346f
implemented worker function to get commits for all projects; also add…
zmike808 7732b4b
cleaned up code & removed unused code
zmike808 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ var UserSchema = new Schema({ | |
| index: true | ||
| }], // project id | ||
|
|
||
|
|
||
| bio: String, | ||
|
|
||
| password: { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,191 @@ | ||
| 'use strict'; | ||
|
|
||
| if (!module.parent) { | ||
| // Set default node environment to development | ||
| process.env.NODE_ENV = process.env.NODE_ENV || 'development'; | ||
|
|
||
| var mongoose = require('mongoose'); | ||
| var config = require('../config/environment'); | ||
| var args = process.argv.slice(2); | ||
|
|
||
| // Connect to database | ||
| var db = mongoose.connect(config.mongo.uri, config.mongo.options); | ||
| } | ||
| var Commit = require('../api/commit/commit.model'); | ||
| var Project = require('../api/project/project.model'); | ||
|
|
||
| var Octokat = require('octokat'); | ||
|
|
||
| var Promise = require("bluebird"); | ||
|
|
||
| mongoose.Promise = require('bluebird'); | ||
|
|
||
| /* | ||
| The github token currently needs to be defined in development.js env. | ||
| Since, this is a worker that is currently run individually, it does not have app.js loaded beforehand. | ||
| Meaning, magic env stuff isn't automagically setup. | ||
| @TODO: bring back the magic | ||
| */ | ||
| var gtoken = config.GITHUB_WORKER_TOKEN; | ||
| if (gtoken == "YOUR_KEY") { | ||
| console.error('ERROR: PLEASE SET YOUR GITHUB_WORKER_TOKEN IN DEVELOPMENT.JS TOKEN BEFORE PROCEEDING'); | ||
| throw new Error('ERROR: PLEASE SET YOUR GITHUB_WORKER_TOKEN IN DEVELOPMENT.JS TOKEN BEFORE PROCEEDING'); | ||
| } | ||
|
|
||
| // setup & initilize our github API library | ||
| var octo = new Octokat({ | ||
| token: gtoken | ||
| }); | ||
|
|
||
| /* | ||
| @TODO: add support for filtering commits by date/author/etc.. | ||
| ex: only get commits newer than date x, or only get commits older than date y | ||
| */ | ||
| function fetchCommitsFromProject(owner, repository, config) { | ||
| return fetchAll(octo.repos(owner, repository).commits.fetch, config); | ||
| } | ||
|
|
||
| function fetchAll(fn, args) { | ||
| let acc = []; | ||
| if (!args) { | ||
| args = {per_page: 100}; | ||
| } | ||
| let p = new Promise((resolve, reject) => { | ||
| fn(args).then((val) => { | ||
| acc = acc.concat(val); | ||
| if (val.nextPage) { | ||
| fetchAll(val.nextPage).then((val2) => { | ||
| acc = acc.concat(val2); | ||
| resolve(acc); | ||
| }, reject); | ||
| } else { | ||
| resolve(acc); | ||
| } | ||
| }, reject); | ||
| }); | ||
| return p; | ||
| } | ||
|
|
||
| var saveCommit = function (commitData, project) { | ||
| var newCommit = new Commit(commitData); | ||
| /* | ||
| establish the ownership relationship; i.e. what project does this commit belong to? | ||
| @TODO: setup the inverse relationship(?); i.e. what commits does the project own? | ||
| */ | ||
| newCommit.project = project; | ||
| /* | ||
| manually extract/configure the data to match our Commit schema. | ||
| */ | ||
| newCommit.message = commitData.commit.message; | ||
| newCommit.date = commitData.commit.author.date; | ||
| newCommit.commentCount = commitData.commit.comment_count; | ||
| // Save the new commit model to the db. This is an async operation, so it will be turned into a promise. | ||
| return newCommit.save(); | ||
| }; | ||
|
|
||
| /* | ||
| @promiseObject: JS object containing 2 fields. | ||
| commits: promise array of fetched commits from github | ||
| project: instance of project model that we are fetching the commits for. | ||
| */ | ||
| var saveCommits = saveCommitsFn; | ||
| function saveCommitsFn(promiseObject) { | ||
| console.dir(promiseObject); | ||
| console.log("entering..."); | ||
| // extract the data from the promiseObject | ||
| var commits = promiseObject.commits; | ||
| var project = promiseObject.project; | ||
| // array of Commit.save() operations; to be turned into an array of Promises. | ||
| var commitPromises = []; | ||
| commits.forEach(function (commit) { | ||
| commitPromises.push(saveCommit(commit, project)); | ||
| }); | ||
| // return an array of promises, where each promise is a promise to save the commit model to the DB. | ||
| return Promise.all(commitPromises); | ||
| } | ||
|
|
||
| exports.getCommitsForProjectSinceDate = function (project, date) { | ||
| date = new Date(Date.parse(date)) || new Date(); | ||
| var config = { | ||
| since: date.toISOString() | ||
| }; | ||
| return processProject(project, config); | ||
| }; | ||
|
|
||
| exports.getCommitsForProjectUntilDate = function (project, date) { | ||
| date = new Date(Date.parse(date)) || new Date(); | ||
| var config = { | ||
| ungil: date.toISOString() | ||
| }; | ||
| return processProject(project, config); | ||
| }; | ||
|
|
||
| exports.getCommitsForProject = function (project) { | ||
| return processProject(project); | ||
| }; | ||
|
|
||
| /** | ||
| * | ||
| * @param project: instance of Project model | ||
| * @param config: | ||
| */ | ||
| var fetchCommits = function (project, config) { | ||
| // extract the github username & github repository name to fetch the commits from. | ||
| var owner = project.githubUsername; | ||
| var repository = project.githubProjectName; | ||
|
|
||
| // Config is an optional arguement, so if it isn't pased init it ourselves | ||
| config = config || {}; | ||
|
|
||
| // always set the results per page limit to the maximum, 100, to reduce github API calls | ||
| config["per_page"] = 100; | ||
|
|
||
| /* | ||
| Needed to pass through project model; to saveCommits; but javascript. | ||
| So instead I just tacked it onto an object. | ||
| Promise.props is essentially the same as using Promise.all([]), | ||
| Except it returns an object with arbitrary fields that can be a promise or arbitrary data. | ||
| with an added variable, @project. | ||
| Probably a better way to do this, but I currently can't think of any because javascript. | ||
| */ | ||
|
|
||
| return Promise.props({ | ||
| commits: fetchCommitsFromProject(owner, repository, config), | ||
| project: project, | ||
| }); | ||
| }; | ||
|
|
||
| /* | ||
| For now just a hard coded example/P.O.C using the github repo rcos/observatory3 | ||
| Planning to refactor this "soon(tm)" | ||
| */ | ||
|
|
||
| function processProject(project, config) { | ||
| /* | ||
| flow: | ||
| 1. fetch commits from github for @project | ||
| 2. save fetched commits to db | ||
| 3. disconnect from DB | ||
| */ | ||
| return fetchCommits(project, config).then(saveCommits); | ||
| } | ||
|
|
||
| function processAllProjects() { | ||
| var start = Promise.resolve(); | ||
| return Promise.map(Project.find({}).exec(), function (proj) { | ||
| start = start.then(function () { | ||
| return fetchCommits(proj); | ||
| }); | ||
| return start; | ||
| }).map(saveCommitsFn).then(function (results) { | ||
| console.dir(results); | ||
| console.dir(results.length); | ||
| db.disconnect(); | ||
| }); | ||
| } | ||
|
|
||
| if (!module.parent) { | ||
| if (args.length == 0) { | ||
| processAllProjects(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out
server/config/environment/index.jsfor examples of how to read from the environment variables to set a config variable.