Skip to content

Commit

Permalink
fix: pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
weilinzung committed Nov 30, 2024
1 parent f1bfa0f commit 0015d59
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 136 deletions.
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npm test && npm run lint-staged
47 changes: 35 additions & 12 deletions bin/action.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -92974,6 +92974,8 @@ function extractChannelIdFromChannelName(channelName) {
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const SITE_CHANNEL_QUOTA = 50;
const SITE_CHANNEL_LIVE_SITE = 1;
function interpretChannelDeployResult(deployResult) {
const allSiteResults = Object.values(deployResult.result);
const expireTime = allSiteResults[0].expireTime;
Expand Down Expand Up @@ -93036,19 +93038,40 @@ async function getAllChannels(gacFilename, deployConfig) {
}
}
function getPreviewChannelToRemove(channels, totalPreviewChannelLimit) {
// Filter out live channel(hosting default site) and channels without an expireTime(additional sites)
const previewChannelsOnly = channels.filter(channel => {
var _channel$labels;
return (channel == null || (_channel$labels = channel.labels) == null ? void 0 : _channel$labels.type) !== "live" && !!(channel != null && channel.expireTime);
});
if (previewChannelsOnly.length) {
// Sort preview channels by expireTime
const sortedPreviewChannels = previewChannelsOnly.sort((channelA, channelB) => {
return new Date(channelA.expireTime).getTime() - new Date(channelB.expireTime).getTime();
let totalAllowedPreviewChannels = totalPreviewChannelLimit;
let totalPreviewChannelToSlice = totalPreviewChannelLimit;
if (totalPreviewChannelLimit >= SITE_CHANNEL_QUOTA - SITE_CHANNEL_LIVE_SITE) {
/**
* If the total number of preview channels is greater than or equal to the site channel quota,
* preview channels is the site channel quota minus the live site channel
*
* e.g. 49(total allowed preview channels) = 50(quota) - 1(live site channel)
*/
totalAllowedPreviewChannels = totalPreviewChannelLimit - SITE_CHANNEL_LIVE_SITE;
/**
* If the total number of preview channels is greater than or equal to the site channel quota,
* total preview channels to slice is the site channel quota plus the live site channel plus the current preview deploy
*
* e.g. 52(total preview channels to slice) = 50(site channel quota) + 1(live site channel) + 1 (current preview deploy)
*/
totalPreviewChannelToSlice = SITE_CHANNEL_QUOTA + SITE_CHANNEL_LIVE_SITE + 1;
}
if (channels.length > totalAllowedPreviewChannels) {
// If the total number of channels exceeds the limit, remove the preview channels
// Filter out live channel(hosting default site) and channels without an expireTime(additional sites)
const previewChannelsOnly = channels.filter(channel => {
var _channel$labels;
return (channel == null || (_channel$labels = channel.labels) == null ? void 0 : _channel$labels.type) !== "live" && !!(channel != null && channel.expireTime);
});
// If the total number of preview channels exceeds the limit, return the ones with earlier expireTime
if (sortedPreviewChannels.length > totalPreviewChannelLimit) {
return sortedPreviewChannels.slice(0, sortedPreviewChannels.length - totalPreviewChannelLimit);
if (previewChannelsOnly.length) {
// Sort preview channels by expireTime
const sortedPreviewChannels = previewChannelsOnly.sort((channelA, channelB) => {
return new Date(channelA.expireTime).getTime() - new Date(channelB.expireTime).getTime();
});
// Calculate the number of preview channels to remove
const sliceEnd = totalPreviewChannelToSlice > sortedPreviewChannels.length ? totalPreviewChannelToSlice - sortedPreviewChannels.length : sortedPreviewChannels.length - totalPreviewChannelToSlice;
// Remove the oldest preview channels
return sortedPreviewChannels.slice(0, sliceEnd);
}
} else {
return [];
Expand Down
Loading

0 comments on commit 0015d59

Please sign in to comment.