Skip to content

Commit

Permalink
fix cleanup for branches with special chars (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrybyk authored Feb 1, 2024
1 parent d065e22 commit 3dba1c5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40536,18 +40536,21 @@ const spawnProcess = async (command, args, cwd) => {
});
};

// EXTERNAL MODULE: ./src/helpers.ts
var helpers = __nccwpck_require__(3015);
;// CONCATENATED MODULE: ./src/cleanup.ts




const cleanupOutdatedBranches = async (ghPagesBaseDir) => {
try {
const prefix = 'refs/heads/';
const lsRemote = await spawnProcess('git', ['ls-remote', '--heads']);
const remoteBranches = lsRemote
.split('\n')
.filter((l) => l.includes(prefix))
.map((l) => l.split(prefix)[1]);
.map((l) => (0,helpers/* normalizeBranchName */.i)(l.split(prefix)[1]));
const localBranches = (await promises_.readdir(ghPagesBaseDir, { withFileTypes: true })).filter((d) => d.isDirectory()).map((d) => d.name);
for (const localBranch of localBranches) {
if (!remoteBranches.includes(localBranch)) {
Expand Down Expand Up @@ -40597,11 +40600,13 @@ const cleanupOutdatedReports = async (ghPagesBaseDir, maxReports) => {
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "L": () => (/* binding */ getBranchName)
/* harmony export */ "L": () => (/* binding */ getBranchName),
/* harmony export */ "i": () => (/* binding */ normalizeBranchName)
/* harmony export */ });
const normalizeBranchName = (branchName) => branchName.replaceAll('/', '_').replaceAll('.', '_');
const getBranchName = (gitRef, pull_request) => {
const branchName = pull_request ? pull_request.head.ref : gitRef.replace('refs/heads/', '');
return branchName.replaceAll('/', '_').replaceAll('.', '_');
return normalizeBranchName(branchName);
};


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allure-report-branch-js-action",
"version": "1.1.0",
"version": "1.1.1",
"description": "Allure Report with history per branch",
"main": "index.js",
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion src/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path'
import * as fs from 'fs/promises'
import { spawnProcess } from './spawnProcess.js'
import { normalizeBranchName } from './helpers.js'

export const cleanupOutdatedBranches = async (ghPagesBaseDir: string) => {
try {
Expand All @@ -9,7 +10,7 @@ export const cleanupOutdatedBranches = async (ghPagesBaseDir: string) => {
const remoteBranches = lsRemote
.split('\n')
.filter((l) => l.includes(prefix))
.map((l) => l.split(prefix)[1])
.map((l) => normalizeBranchName(l.split(prefix)[1]))

const localBranches = (await fs.readdir(ghPagesBaseDir, { withFileTypes: true })).filter((d) => d.isDirectory()).map((d) => d.name)

Expand Down
4 changes: 3 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { context } from '@actions/github'

export const normalizeBranchName = (branchName: string) => branchName.replaceAll('/', '_').replaceAll('.', '_')

export const getBranchName = (gitRef: string, pull_request?: (typeof context)['payload']) => {
const branchName: string = pull_request ? pull_request.head.ref : gitRef.replace('refs/heads/', '')

return branchName.replaceAll('/', '_').replaceAll('.', '_')
return normalizeBranchName(branchName)
}

0 comments on commit 3dba1c5

Please sign in to comment.