mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Create an action for determine the complexity
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
name: Determine Complexity
|
||||
description: 'Determine the complexity of the PR'
|
||||
|
||||
inputs:
|
||||
file-changed-limit:
|
||||
description: 'The limit of files changed in the PR to throw a major complexity'
|
||||
required: true
|
||||
type: number
|
||||
lines-changed-limit:
|
||||
description: 'The limit of lines changed in the PR to throw a major complexity'
|
||||
required: true
|
||||
type: number
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||
- name: Determine complexity
|
||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||
env:
|
||||
file-changed-limit: ${{ inputs.file-changed-limit }}
|
||||
line-changed-limit: ${{ inputs.lines-changed-limit }}
|
||||
with:
|
||||
script: |
|
||||
console.log('Determine Complexity');
|
||||
console.log(`File changed limit: ${process.env.fileChangedLimit}`);
|
||||
const determineComplexity = require('./.github/actions/determine-complexity/determine-pr-complexity.js');
|
||||
|
||||
determineComplexity({
|
||||
core,
|
||||
github,
|
||||
context,
|
||||
fileChangedLimit: process.env.fileChangedLimit,
|
||||
lineChangedLimit: process.env.lineChangedLimit
|
||||
});
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
async function getPRDetails(github, core, owner, repo, pull_number) {
|
||||
core.info(`Fetching PR details`);
|
||||
|
||||
const { data: files } = await github.pulls.listFiles({
|
||||
owner,
|
||||
repo,
|
||||
pull_number
|
||||
});
|
||||
|
||||
core.info(`Fetched PR details: ${JSON.stringify(files)}`);
|
||||
|
||||
let filesChanged = files.length;
|
||||
let linesChanged = files.reduce((total, file) => total + file.additions + file.deletions, 0);
|
||||
|
||||
let level = 'unknown';
|
||||
let packageName = 'unknown';
|
||||
let packagesAffected = new Set();
|
||||
for (let file of files) {
|
||||
if (file.filename.startsWith('lib/core/')) {
|
||||
if (file.filename.startsWith('lib/core/auth/')) {
|
||||
level = 'extreme';
|
||||
}
|
||||
level = 'major';
|
||||
packageName = 'core';
|
||||
packagesAffected.add(packageName);
|
||||
break;
|
||||
} else if (file.filename.startsWith('lib/extensions/')) {
|
||||
level = 'major';
|
||||
packageName = 'extensions';
|
||||
packagesAffected.add(packageName);
|
||||
|
||||
break;
|
||||
} else {
|
||||
level = 'minor';
|
||||
packagesAffected.add(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
if (level !== 'major') {
|
||||
if (linesChanged > 100) {
|
||||
level = 'major';
|
||||
} else if (linesChanged > 50) {
|
||||
level = 'medium';
|
||||
}
|
||||
}
|
||||
|
||||
if (level !== 'major') {
|
||||
if (filesChanged > 10) {
|
||||
level = 'major';
|
||||
} else if (filesChanged > 5) {
|
||||
level = 'medium';
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
filesChanged,
|
||||
linesChanged,
|
||||
level: level,
|
||||
packagesAffected: Array.from(packagesAffected)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = async ({ core, github, context, fileChangedLimit = 5, linesChangedLimit = 50 }) => {
|
||||
const owner = context.repo.owner;
|
||||
const repo = context.repo.repo;
|
||||
const pull_number = context.payload.pull_request.number;
|
||||
|
||||
core.info(`Getting PR details for ${owner}/${repo}#${pull_number}`);
|
||||
core.info(`Limit for files changed: ${fileChangedLimit}`);
|
||||
core.info(`Limit for lines changed: ${linesChangedLimit}`);
|
||||
|
||||
const details = await getPRDetails(github, owner, repo, pull_number);
|
||||
|
||||
core.info(`PR details: ${JSON.stringify(details)}`);
|
||||
};
|
||||
@@ -509,9 +509,10 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: Determine complexity
|
||||
id: complexity
|
||||
run: |
|
||||
echo "level=major" >> $GITHUB_OUTPUT
|
||||
uses: ./.github/actions/determine-complexity
|
||||
with:
|
||||
file-changed-limit: 10
|
||||
lines-changed-limit: 100
|
||||
|
||||
verify-downstream:
|
||||
needs: determine-complexity
|
||||
|
||||
Reference in New Issue
Block a user