Skip to content

Commit

Permalink
#35: create sagas and get commit, branch and stakeholders data from d…
Browse files Browse the repository at this point in the history
…atabase

  create sagas/index.js with all createActions and get colorPalettes for the CheckboxLegend, create files for getting commit, branch and stakeholders data from database.
  • Loading branch information
miriamgehbauer committed Nov 3, 2021
1 parent a22da4a commit a6966eb
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ui/src/visualizations/File-Evolution/sagas/getBranches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

import { traversePages, graphQl } from '../../../utils';

/**
* Get branches from the database.
* @returns {*}
*/
export default function getBranches() {
const branchList = [];

return traversePages(getBranchPage(), branch => {
branchList.push(branch);
}).then(function() {
return branchList;
});
}

const getBranchPage = until => (page, perPage) => {
return graphQl
.query(
`query ($page: Int, $perPage: Int) {
branches(page: $page, perPage: $perPage, sort: "ASC") {
count
data{
id
branch
active
}
}
}`,
{ page, perPage }
)
.then(resp => resp.branches);
};
42 changes: 42 additions & 0 deletions ui/src/visualizations/File-Evolution/sagas/getCommitData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

import { traversePages, graphQl } from '../../../utils';

/**
* Get commit data from the database.
* @returns {*}
*/
export default function getCommitData() {
const commitList = [];

return traversePages(getCommitsPage(), commit => {
commitList.push(commit);
}).then(function() {
return commitList;
});
}

const getCommitsPage = until => (page, perPage) => {
return graphQl
.query(
`query($page: Int, $perPage: Int) {
commits(page: $page, perPage: $perPage, sort: "ASC" ) {
count
data {
sha
date
message
messageHeader
signature
webUrl
stats {
additions
deletions
}
}
}
}`,
{ page, perPage, until }
)
.then(resp => resp.commits);
};
31 changes: 31 additions & 0 deletions ui/src/visualizations/File-Evolution/sagas/getCommiters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

import { traversePages, graphQl } from '../../../utils';

/**
* @returns {*} (see below)
*/
export default function getCommiters() {
const committers = [];

return traversePages(getCommittersPage(), stakeholders => {
committers.push(stakeholders);
}).then(function() {
return committers;
});
}

const getCommittersPage = until => (page, perPage) => {
return graphQl
.query(
`query ($page: Int, $perPage: Int) {
stakeholders(page: $page, perPage: $perPage) {
data{
gitSignature,
}
}
}`,
{ page, perPage, until }
)
.then(resp => resp.stakeholders);
};
111 changes: 111 additions & 0 deletions ui/src/visualizations/File-Evolution/sagas/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict';

import Promise from 'bluebird';
import { createAction } from 'redux-actions';
import { throttle, fork, takeEvery, select } from 'redux-saga/effects';

import { fetchFactory, timestampedActionFactory, mapSaga } from '../../../sagas/utils.js';
import getCommitData from './getCommitData.js';
import getBranches from './getBranches.js';
import getCommiters from './getCommiters.js';

export const setCommitBoxHeight = createAction('SET_COMMIT_BOX_HEIGHT');
export const setCommitBoxWidth = createAction('SET_COMMIT_BOX_WIDTH');
export const setCommitBoxColor = createAction('SET_COMMIT_BOX_COLOR');

export const setSelectedAuthors = createAction('SET_SELECTED_AUTHORS');
export const setSelectedBranches = createAction('SET_SELECTED_BRANCHES');

export const setShowCommitDate = createAction('SET_SHOW_COMMIT_DATE');
export const setShowCommitMessage = createAction('SET_SHOW_COMMIT_MESSAGE');
export const setShowCommitAuthor = createAction('SET_SHOW_COMMIT_AUTHOR');

export const requestFileEvolutionData = createAction('REQUEST_FILE_EVOLUTION_DATA');
export const receiveFileEvolutionData = timestampedActionFactory('RECEIVE_FILE_EVOLUTION_DATA');
export const receiveFileEvolutionDataError = createAction('RECEIVE_FILE_EVOLUTION_DATA_ERROR');

export const requestRefresh = createAction('REQUEST_REFRESH');
const refresh = createAction('REFRESH');

export default function*() {
// fetch data once on entry
yield* fetchFileEvolutionData();

yield fork(watchRefreshRequests);
yield fork(watchMessages);

// keep looking for viewport changes to re-fetch
yield fork(watchRefresh);
yield fork(watchToggleHelp);
}

function* watchRefreshRequests() {
yield throttle(2000, 'REQUEST_REFRESH', mapSaga(refresh));
}

function* watchMessages() {
yield takeEvery('message', mapSaga(requestRefresh));
}

function* watchToggleHelp() {
yield takeEvery('TOGGLE_HELP', mapSaga(refresh));
}

function* watchRefresh() {
yield takeEvery('REFRESH', fetchFileEvolutionData);
}

/**
* Fetch data for FILE EVOLUTION, this still includes old functions that were copied over.
*/
export const fetchFileEvolutionData = fetchFactory(
function*() {
//const commiters = yield getCommiters();
return yield Promise.join(getCommitData(), getBranches(), getCommiters())
.spread((commits, branches, commiters) => {
const authorsColorPalette = getAuthorColorPalette(commiters);
const branchesColorPalette = getBranchesColorPalette(branches);
return {
commits,
branches,
commiters,
authorsColorPalette,
branchesColorPalette
};
})
.catch(function(e) {
console.error(e.stack);
throw e;
});
},
requestFileEvolutionData,
receiveFileEvolutionData,
receiveFileEvolutionDataError
);

function getAuthorColorPalette(commiters) {
//TODO Color???
const colorPalette = {};
for (const i in commiters) {
let randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
while (randomColor.length !== 7) {
randomColor = randomColor + '0';
}
colorPalette[commiters[i].gitSignature] = randomColor;
}
return colorPalette;
}

function getBranchesColorPalette(branches) {
//TODO Color???
const colorPalette = {};
for (const i in branches) {
let randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
while (randomColor.length !== 7) {
randomColor = randomColor + '0';
}
colorPalette[branches[i].branch] = randomColor;
}
console.log(colorPalette);
return colorPalette;
}

0 comments on commit a6966eb

Please sign in to comment.