mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
* increase timeout and modify login async * run e2e if testing is changed * improve cdk fix * fix travis update projects * disable ghostMode lite server * lint fix * fix timeout * multiple try * Update content-services-e2e.sh * Update search-e2e.sh * Update process-services-e2e.sh * Update core-e2e.sh * Update protractor.conf.ts * fix unit * remove async * increqase notification time * 3 parallel * dix path issue in save * small refactor protractor ts * fix save * create license check first script adf cli * modify regex check * refactor notification history component * decrease notification * fix notification message problem * fix test * update packages wit high risk * revert cahnge login sso e2e * fix dep * fix documentation duplication and issue * fix after review * fix after review * try 6 parallel test * back to 3 parallel test no real time improve with 6
166 lines
4.2 KiB
TypeScript
166 lines
4.2 KiB
TypeScript
import * as path from "path";
|
|
import * as fs from "fs";
|
|
import * as process from "process"
|
|
|
|
import { GraphQLClient } from "graphql-request";
|
|
import * as remark from "remark";
|
|
import * as frontMatter from "remark-frontmatter";
|
|
import * as yaml from "js-yaml";
|
|
import * as moment from "moment";
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
import * as libsearch from "./libsearch";
|
|
import { Stoplist } from "./stoplist";
|
|
import { last } from "rxjs/operator/last";
|
|
|
|
|
|
const adf20StartDate = "2017-11-20";
|
|
|
|
const commitWeight = 0.1;
|
|
const scoreTimeBase = 60;
|
|
|
|
const libFolder = "lib";
|
|
const stoplistFilePath = path.resolve("tools", "doc", "commitStoplist.json");
|
|
|
|
const angFilePattern = /(component)|(directive)|(model)|(pipe)|(service)|(widget)/;
|
|
|
|
let srcData = {};
|
|
let stoplist = new Stoplist(stoplistFilePath);
|
|
|
|
let docsFolderPath = path.resolve("docs");
|
|
|
|
let libFolders = ["core", "content-services", "extensions", "insights", "process-services", "process-services-cloud"];
|
|
|
|
libsearch(srcData, path.resolve(libFolder));
|
|
|
|
const authToken = process.env.graphAuthToken;
|
|
|
|
const client = new GraphQLClient('https://api.github.com/graphql', {
|
|
headers: {
|
|
Authorization: 'Bearer ' + authToken
|
|
}
|
|
});
|
|
|
|
const query = `query commitHistory($path: String) {
|
|
repository(name: "alfresco-ng2-components", owner: "alfresco") {
|
|
ref(qualifiedName: "development") {
|
|
target {
|
|
... on Commit {
|
|
history(first: 15, path: $path) {
|
|
nodes {
|
|
pushedDate
|
|
message
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`;
|
|
|
|
let docFiles = getDocFilePaths(docsFolderPath);
|
|
|
|
let docNames = Observable.from(docFiles);
|
|
|
|
console.log("'Name','Review date','Commits since review','Score'");
|
|
|
|
docNames.subscribe(x => {
|
|
let key = path.basename(x, ".md");
|
|
|
|
if (!srcData[key])
|
|
return;
|
|
|
|
let vars = {
|
|
"path": "lib/" + srcData[key].path
|
|
};
|
|
|
|
client.request(query, vars).then(data => {
|
|
let nodes = data["repository"].ref.target.history.nodes;
|
|
|
|
let lastReviewDate = getDocReviewDate(x);//(key + ".md");
|
|
|
|
let numUsefulCommits = extractCommitInfo(nodes, lastReviewDate, stoplist);
|
|
let dateString = lastReviewDate.format("YYYY-MM-DD");
|
|
let score = priorityScore(lastReviewDate, numUsefulCommits).toPrecision(3);
|
|
|
|
console.log(`'${key}','${dateString}','${numUsefulCommits}','${score}'`);
|
|
});
|
|
});
|
|
|
|
|
|
function priorityScore(reviewDate, numCommits) {
|
|
let daysSinceReview = moment().diff(reviewDate, 'days');
|
|
let commitScore = 2 + numCommits * commitWeight;
|
|
return Math.pow(commitScore, daysSinceReview / scoreTimeBase);
|
|
}
|
|
|
|
|
|
function getDocReviewDate(docFileName) {
|
|
let mdFilePath = path.resolve(docsFolderPath, docFileName);
|
|
|
|
let mdText = fs.readFileSync(mdFilePath);
|
|
let tree = remark().use(frontMatter, ["yaml"]).parse(mdText);
|
|
|
|
let lastReviewDate = moment(adf20StartDate);
|
|
|
|
if (tree.children[0].type == "yaml") {
|
|
let metadata = yaml.load(tree.children[0].value);
|
|
|
|
if (metadata["Last reviewed"])
|
|
lastReviewDate = moment(metadata["Last reviewed"]);
|
|
}
|
|
|
|
return lastReviewDate;
|
|
}
|
|
|
|
|
|
function extractCommitInfo(commitNodes, cutOffDate, stoplist) {
|
|
let numUsefulCommits = 0;
|
|
|
|
commitNodes.forEach(element => {
|
|
if (!stoplist.isRejected(element.message)) {
|
|
let abbr = element.message.substr(0, 15);
|
|
|
|
let commitDate = moment(element.pushedDate);
|
|
|
|
if (commitDate.isAfter(cutOffDate)) {
|
|
numUsefulCommits++;
|
|
}
|
|
}
|
|
});
|
|
|
|
return numUsefulCommits;
|
|
}
|
|
|
|
|
|
function getDocFilePaths(folderPath) {
|
|
let result = [];
|
|
|
|
libFolders.forEach(element => {
|
|
let libPath = path.resolve(folderPath, element);
|
|
addItemsRecursively(libPath, result);
|
|
});
|
|
|
|
|
|
return result;
|
|
|
|
function addItemsRecursively(folderPath: string, resultList: string[]) {
|
|
let items = fs.readdirSync(folderPath);
|
|
|
|
items.forEach(item => {
|
|
let fullItemPath = path.resolve(folderPath, item);
|
|
let itemInfo = fs.statSync(fullItemPath);
|
|
|
|
if (itemInfo.isDirectory()) {
|
|
addItemsRecursively(fullItemPath, resultList);
|
|
} else if (
|
|
(path.extname(fullItemPath) === ".md") &&
|
|
(item !== "README.md") &&
|
|
(item.match(angFilePattern))
|
|
) {
|
|
resultList.push(fullItemPath);
|
|
}
|
|
});
|
|
}
|
|
}
|