Skip to content

Commit

Permalink
Web: Studio: Init Debug Info
Browse files Browse the repository at this point in the history
+ Added About version from package.json
+ Fix DocumentServer version
  • Loading branch information
AlexeySafronov committed Oct 4, 2021
1 parent 645f0aa commit 9ce696e
Show file tree
Hide file tree
Showing 27 changed files with 1,723 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Data/
Logs/
**/.DS_Store
.eslintcache
build/deploy/
build/deploy/
/public/debuginfo.md
2 changes: 1 addition & 1 deletion config/nginx/onlyoffice.conf
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ server {
location / {

proxy_pass http://localhost:5001;
location ~* /(manifest.json|sw.js|appIcon.png|bg-error.png|favicon.ico) {
location ~* /(manifest.json|sw.js|appIcon.png|bg-error.png|favicon.ico|debuginfo.md) {
root $public_root;
try_files /$basename /index.html =404;
}
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"packages/asc-web-components",
"packages/asc-web-common",
"packages/browserslist-config-asc",
"packages/debug-info",
"web/ASC.Web.Login",
"web/ASC.Web.Client",
"web/ASC.Web.Editor",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"packages/asc-web-components",
"packages/asc-web-common",
"packages/browserslist-config-asc",
"packages/debug-info",
"web/ASC.Web.Login",
"web/ASC.Web.Client",
"web/ASC.Web.Editor",
Expand Down Expand Up @@ -44,7 +45,8 @@
"sw-studio-login-replace": "replace-in-files --string='studio/login/' --replacement='login/' build/deploy/public/sw.js",
"sw-studio-replace": "replace-in-files --string='studio/client/' --replacement='/' build/deploy/public/sw.js",
"test": "yarn workspace @appserver/components test",
"wipe": "shx rm -rf node_modules yarn.lock web/**/node_modules products/**/node_modules"
"wipe": "shx rm -rf node_modules yarn.lock web/**/node_modules products/**/node_modules",
"debug-info": "node packages/debug-info/src/index.js --unreleased-only --template debuginfo --output public/debuginfo.md"
},
"devDependencies": {
"browserslist": "^4.17.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/asc-web-common/api/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,11 @@ export function getCommonThirdPartyList() {
};
return request(options);
}

export function getBuildVersion() {
const options = {
method: "get",
url: "/settings/version/build.json",
};
return request(options);
}
23 changes: 22 additions & 1 deletion packages/asc-web-common/store/SettingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ARTICLE_PINNED_KEY, LANGUAGE } from "../constants";
import { combineUrl } from "../utils";
import FirebaseHelper from "../utils/firebase";
import { AppServerConfig } from "../constants";
import { version } from "../package.json";
const { proxyURL } = AppServerConfig;

class SettingsStore {
Expand Down Expand Up @@ -85,6 +86,10 @@ class SettingsStore {
measurementId: "",
};
version = "";
buildVersionInfo = {
appServer: version,
documentServer: "6.4.1",
};

constructor() {
makeAutoObservable(this);
Expand Down Expand Up @@ -183,7 +188,7 @@ class SettingsStore {
init = async () => {
this.setIsLoading(true);

await this.getPortalSettings();
await Promise.all([this.getPortalSettings(), this.getBuildVersionInfo()]);

this.setIsLoading(false);
this.setIsLoaded(true);
Expand Down Expand Up @@ -329,6 +334,22 @@ class SettingsStore {
window.firebaseHelper = new FirebaseHelper(this.firebase);
return window.firebaseHelper;
}

getBuildVersionInfo = async () => {
const versionInfo = await api.settings.getBuildVersion();
this.setBuildVersionInfo(versionInfo);
};

setBuildVersionInfo = (versionInfo) => {
this.buildVersionInfo = {
...this.buildVersionInfo,
appServer: version,
...versionInfo,
};

if (!this.buildVersionInfo.documentServer)
this.buildVersionInfo.documentServer = "6.4.1";
};
}

export default SettingsStore;
32 changes: 32 additions & 0 deletions packages/debug-info/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@appserver/debuginfo",
"version": "0.0.1",
"description": "Command line tool for generating debug info by commit history",
"main": "./src/index.js",
"engines": {
"node": ">=8.3"
},
"dependencies": {
"commander": "^7.2.0",
"handlebars": "^4.7.7",
"node-fetch": "^2.6.5",
"parse-github-url": "^1.0.2",
"semver": "^7.3.5"
},
"nyc": {
"all": true,
"include": "src",
"exclude": "src/index.js",
"sourceMap": false,
"instrument": false,
"report-dir": "./coverage",
"temp-dir": "./coverage/.nyc_output",
"require": [
"@babel/register"
],
"reporter": [
"text",
"html"
]
}
}
167 changes: 167 additions & 0 deletions packages/debug-info/src/commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
const semver = require("semver");
const {
cmd,
isLink,
encodeHTML,
niceDate,
replaceText,
getGitVersion,
} = require("./utils");

const COMMIT_SEPARATOR = "__AUTO_CHANGELOG_COMMIT_SEPARATOR__";
const MESSAGE_SEPARATOR = "__AUTO_CHANGELOG_MESSAGE_SEPARATOR__";
const MATCH_COMMIT = /(.*)\n(.*)\n(.*)\n(.*)\n([\S\s]+)/;
const MATCH_STATS = /(\d+) files? changed(?:, (\d+) insertions?...)?(?:, (\d+) deletions?...)?/;
const BODY_FORMAT = "%B";
const FALLBACK_BODY_FORMAT = "%s%n%n%b";

// https://help.github.com/articles/closing-issues-via-commit-messages
const DEFAULT_FIX_PATTERN = /(?:close[sd]?|fixe?[sd]?|resolve[sd]?)\s(?:#(\d+)|(https?:\/\/.+?\/(?:issues|pull|pull-requests|merge_requests)\/(\d+)))/gi;

const MERGE_PATTERNS = [
/^Merge pull request #(\d+) from .+\n\n(.+)/, // Regular GitHub merge
/^(.+) \(#(\d+)\)(?:$|\n\n)/, // Github squash merge
/^Merged in .+ \(pull request #(\d+)\)\n\n(.+)/, // BitBucket merge
/^Merge branch .+ into .+\n\n(.+)[\S\s]+See merge request [^!]*!(\d+)/, // GitLab merge
];

const fetchCommits = async (diff, options = {}) => {
const format = await getLogFormat();
const log = await cmd(
`git log ${diff} --shortstat --pretty=format:${format} ${options.appendGitLog}`
);
return parseCommits(log, options);
};

const getLogFormat = async () => {
const gitVersion = await getGitVersion();
const bodyFormat =
gitVersion && semver.gte(gitVersion, "1.7.2")
? BODY_FORMAT
: FALLBACK_BODY_FORMAT;
return `${COMMIT_SEPARATOR}%H%n%ai%n%an%n%ae%n${bodyFormat}${MESSAGE_SEPARATOR}`;
};

const parseCommits = (string, options = {}) => {
return string
.split(COMMIT_SEPARATOR)
.slice(1)
.map((commit) => parseCommit(commit, options))
.filter((commit) => filterCommit(commit, options));
};

const parseCommit = (commit, options = {}) => {
const [, hash, date, author, email, tail] = commit.match(MATCH_COMMIT);
const [body, stats] = tail.split(MESSAGE_SEPARATOR);
const message = encodeHTML(body);
const parsed = {
hash,
shorthash: hash.slice(0, 7),
author,
email,
date: new Date(date).toISOString(),
niceDate: niceDate(new Date(date)),
subject: replaceText(getSubject(message), options),
message: message.trim(),
fixes: getFixes(message, author, options),
href: options.getCommitLink(hash),
breaking:
!!options.breakingPattern &&
new RegExp(options.breakingPattern).test(message),
...getStats(stats),
};
return {
...parsed,
merge: getMerge(parsed, message, options),
};
};

const getSubject = (message) => {
if (!message.trim()) {
return "_No commit message_";
}
return message.match(/[^\n]+/)[0];
};

const getStats = (stats) => {
if (!stats.trim()) return {};
const [, files, insertions, deletions] = stats.match(MATCH_STATS);
return {
files: parseInt(files || 0),
insertions: parseInt(insertions || 0),
deletions: parseInt(deletions || 0),
};
};

const getFixes = (message, author, options = {}) => {
const pattern = getFixPattern(options);
const fixes = [];
let match = pattern.exec(message);
if (!match) return null;
while (match) {
const id = getFixID(match);
const href = isLink(match[2]) ? match[2] : options.getIssueLink(id);
fixes.push({ id, href, author });
match = pattern.exec(message);
}
return fixes;
};

const getFixID = (match) => {
// Get the last non-falsey value in the match array
for (let i = match.length; i >= 0; i--) {
if (match[i]) {
return match[i];
}
}
};

const getFixPattern = (options) => {
if (options.issuePattern) {
return new RegExp(options.issuePattern, "g");
}
return DEFAULT_FIX_PATTERN;
};

const getMergePatterns = (options) => {
if (options.mergePattern) {
return MERGE_PATTERNS.concat(new RegExp(options.mergePattern, "g"));
}
return MERGE_PATTERNS;
};

const getMerge = (commit, message, options = {}) => {
const patterns = getMergePatterns(options);
for (const pattern of patterns) {
const match = pattern.exec(message);
if (match) {
const id = /^\d+$/.test(match[1]) ? match[1] : match[2];
const message = /^\d+$/.test(match[1]) ? match[2] : match[1];
return {
id,
message: replaceText(message, options),
href: options.getMergeLink(id),
author: commit.author,
commit,
};
}
}
return null;
};

const filterCommit = (commit, { ignoreCommitPattern }) => {
if (
ignoreCommitPattern &&
new RegExp(ignoreCommitPattern).test(commit.subject)
) {
return false;
}
return true;
};

module.exports = {
COMMIT_SEPARATOR,
MESSAGE_SEPARATOR,
fetchCommits,
parseCommit,
};
9 changes: 9 additions & 0 deletions packages/debug-info/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

const { run } = require('./run')

run(process.argv).catch(error => {
console.log('\n')
console.error(error)
process.exit(1)
})
Loading

0 comments on commit 9ce696e

Please sign in to comment.