Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash on large binary files #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8487,7 +8487,9 @@ const sliceChars = (file, maxTokens) => {
};

module.exports = (str, maxTokens) => {
const files = str.split(new RegExp(`\n${FILES_SPLIT}`, 'g'));
// Remove binary patches as they are not needed and can be very large.
const formated = str.replace(/(?:GIT binary patch)(\ndelta.*\s*)(?:[diff --git]|$)/gmsu, 'GIT binary patch');
const files = formated.split(new RegExp(`\n${FILES_SPLIT}`, 'g'));
files.sort((a, b) => a.length - b.length);

let tokens = 0;
Expand Down Expand Up @@ -12608,7 +12610,7 @@ module.exports = function bind(fn, thisArg) {
/***/ 731:
/***/ (function(module) {

module.exports = {"name":"recap","version":"1.0.0","description":"Github action to summarize the most important changes in a pull request","main":"dist/index.js","scripts":{"build":"eslint src && ncc build src/entrypoint.js","test":"jest","lint":"eslint ./"},"keywords":[],"author":"Manuel de la Torre","license":"MIT","jest":{"testEnvironment":"node","setupFilesAfterEnv":["./tests/setup.js"],"testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"]},"dependencies":{"@actions/core":"^1.5.0","@actions/github":"^5.0.0","axios":"^0.26.1","i18n-js":"^3.9.2","lodash.get":"^4.4.2","mixpanel":"^0.13.0"},"devDependencies":{"@zeit/ncc":"^0.22.3","eslint":"^7.32.0","eslint-config-airbnb-base":"^14.2.1","eslint-plugin-import":"^2.24.1","eslint-plugin-jest":"^24.4.0","jest":"^27.0.6","jest-extended":"^3.2.4","nock":"^13.3.0"},"funding":"https://github.com/sponsors/manuelmhtr"};
module.exports = {"name":"recap","version":"1.0.1","description":"Github action to summarize the most important changes in a pull request","main":"dist/index.js","scripts":{"build":"eslint src && ncc build src/entrypoint.js","test":"jest","lint":"eslint ./"},"keywords":[],"author":"Manuel de la Torre","license":"MIT","jest":{"testEnvironment":"node","setupFilesAfterEnv":["./tests/setup.js"],"testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"]},"dependencies":{"@actions/core":"^1.5.0","@actions/github":"^5.0.0","axios":"^0.26.1","i18n-js":"^3.9.2","lodash.get":"^4.4.2","mixpanel":"^0.13.0"},"devDependencies":{"@zeit/ncc":"^0.22.3","eslint":"^7.32.0","eslint-config-airbnb-base":"^14.2.1","eslint-plugin-import":"^2.24.1","eslint-plugin-jest":"^24.4.0","jest":"^27.0.6","jest-extended":"^3.2.4","nock":"^13.3.0"},"funding":"https://github.com/sponsors/manuelmhtr"};

/***/ }),

Expand Down
4 changes: 3 additions & 1 deletion src/utils/limitTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const sliceChars = (file, maxTokens) => {
};

module.exports = (str, maxTokens) => {
const files = str.split(new RegExp(`\n${FILES_SPLIT}`, 'g'));
// Remove binary patches as they are not needed and can be very large.
const formated = str.replace(/(?:GIT binary patch)(\ndelta.*\s*)(?:[diff --git]|$)/gmsu, 'GIT binary patch');
const files = formated.split(new RegExp(`\n${FILES_SPLIT}`, 'g'));
files.sort((a, b) => a.length - b.length);

let tokens = 0;
Expand Down