!8835 新增比较历史版本jsdoc功能

Merge pull request !8835 from 王青/diff_change
This commit is contained in:
openharmony_ci 2024-01-22 07:58:48 +00:00 committed by Gitee
commit 9c8db0fef4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 63 additions and 1 deletions

View File

@ -17,6 +17,7 @@ const ts = require('typescript');
const { ApiDigestInfo } = require('./api_data');
const { DiffReporter } = require('./reporter');
const { StatusCode } = require('./reporter');
const { getCheckApiVersion } = require('../../api_check_plugin/src/utils')
class TagItem {
constructor() { }
@ -253,6 +254,7 @@ function compareJSDocs(oldApi, newApi, diffReporter) {
const newTagItem = getTagItemFromJSDoc(newApi);
const useinstead = getApiUseInstead(newApi);
const hint = useinstead.length > 0 ? `useinstead: ${useinstead[0]}` : '';
diffHistoricalJsDoc(oldApi, newApi, diffReporter, hint);
diffErrorCode(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
diffPermission(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
diffForm(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
@ -263,6 +265,64 @@ function compareJSDocs(oldApi, newApi, diffReporter) {
diffType(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
}
function getLatestVersion(jsdocs) {
if (!jsdocs) {
return;
}
const jsdoc = jsdocs[jsdocs.length - 1];
let apiLatestVersion = '';
jsdoc.tags.forEach(tagObject => {
if (tagObject.tag === 'since') {
apiLatestVersion = tagObject.name;
}
})
return apiLatestVersion;
}
function diffHistoricalJsDoc(oldApi, newApi, diffReporter, hint) {
const currentVersion = getCheckApiVersion();
const oldJsDocTextArr = oldApi.getAstNode().getFullText().replace(oldApi.getAstNode().getText(), '').split('*/');
const newJsDocTextArr = newApi.getAstNode().getFullText().replace(oldApi.getAstNode().getText(), '').split('*/');
if (!oldApi.jsdoc) {
return;
}
const oldLatestVersion = getLatestVersion(oldApi.jsdoc);
const newLatestVersion = getLatestVersion(newApi.jsdoc);
if (oldLatestVersion === currentVersion) {
oldJsDocTextArr.splice(-2);
} else {
oldJsDocTextArr.splice(-1);
}
if (newLatestVersion === currentVersion) {
newJsDocTextArr.splice(-2);
} else {
newJsDocTextArr.splice(-1);
}
if (oldJsDocTextArr.length !== newJsDocTextArr.length) {
diffReporter.addDiffInfo(wrapApiChanges(newApi, StatusCode.HOSTORICAL_JSDOC_CHANGE,
'',
'',
hint,
oldApi.node,
newApi.node
));
return;
}
for (let i = 0; i < oldJsDocTextArr.length; i++) {
if (oldJsDocTextArr[i].replace(/\r|\n|\s+/g, '') !== newJsDocTextArr[i].replace(/\r|\n|\s+/g, '')) {
diffReporter.addDiffInfo(wrapApiChanges(newApi, StatusCode.HOSTORICAL_JSDOC_CHANGE,
'',
'',
hint,
oldApi.node,
newApi.node
));
}
}
}
/**
* 比较@type
*
@ -708,7 +768,7 @@ function createTagItemFromJSDoc(jsdocs) {
}
});
}
if (firstJsDoc.tags) {
firstJsDoc.tags.forEach((tagObject) => {
if (tagObject.tag.toLowerCase() === 'since') {

View File

@ -39,6 +39,7 @@ const ApiStatusCode = {
CROSSPLATFORM_CHANGED: 20,
NEW_DTS: 21,
NEW_CLASS: 22,
HOSTORICAL_JSDOC_CHANGE: 23
};
const StatusMessages = [];
@ -65,6 +66,7 @@ StatusMessages[ApiStatusCode.CHANGELOG] = 'changelog';
StatusMessages[ApiStatusCode.DTS_CHANGED] = 'd.ts有变化';
StatusMessages[ApiStatusCode.FORM_CHANGED] = '卡片应用支持性有变化';
StatusMessages[ApiStatusCode.CROSSPLATFORM_CHANGED] = '跨平台能力有变化';
StatusMessages[ApiStatusCode.HOSTORICAL_JSDOC_CHANGE] = '历史jsdoc有变化';
function reportDeletedApi(api, syscap) {
return wrapApiDiffInfo(api, ApiStatusCode.DELETE, '', '', '', syscap);