Skip to content

Commit

Permalink
fix: image or video CDN url (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
nejdetkadir authored Oct 3, 2024
1 parent 6a1ac26 commit 6147ac6
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dist/index.js

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"package": "ncc build src/index.ts --license licenses.txt",
"package:watch": "npm run package -- --watch",
"test": "(jest && make-coverage-badge --output-path ./badges/coverage.svg) || make-coverage-badge --output-path ./badges/coverage.svg",
"all": "npm run format:write && npm run lint && npm run test && npm run package"
"all": "npm run format:write && npm run lint && npm run test && npm run package",
"release": "chmod +x ./scripts/release.sh && ./scripts/release.sh"
},
"license": "MIT",
"jest": {
Expand Down Expand Up @@ -87,4 +88,4 @@
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
}
}
134 changes: 134 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
release_type=$1
version=""

if [ -z "$release_type" ]; then
release_type="--patch"
fi

if [ "$release_type" = "--major" ]; then
release_type="major"
elif [ "$release_type" = "--minor" ]; then
release_type="minor"
elif [ "$release_type" = "--patch" ]; then
release_type="patch"
else
if [[ $release_type == v* ]]; then
version=$release_type
else
echo "Invalid release type"
exit 1
fi
fi

function git_installed() {
command -v git >/dev/null 2>&1
}

function inside_git_repo() {
git rev-parse --is-inside-work-tree >/dev/null 2>&1
}

function tag_list() {
git tag --list
}

function latest_tag() {
local list=$(tag_list)
echo "$list" | sort -V | tail -n 1
}

function new_tag() {
if [ -z "$(tag_list)" ]; then
echo "v1.0.0"
else
local release_type=$1
local latest_tag=$(latest_tag)

local major=$(echo $latest_tag | cut -d. -f1 | sed 's/v//')
local minor=$(echo $latest_tag | cut -d. -f2)
local patch=$(echo $latest_tag | cut -d. -f3)

if [ -z "$release_type" ]; then
release_type="patch"
fi

if [ "$release_type" = "major" ]; then
major=$((major + 1))
minor=0
patch=0
elif [ "$release_type" = "minor" ]; then
minor=$((minor + 1))
patch=0
elif [ "$release_type" = "patch" ]; then
patch=$((patch + 1))
fi

echo "v$major.$minor.$patch"
fi
}

function gh_cli_installed() {
command -v gh >/dev/null 2>&1
}

function gh_cli_logined() {
gh auth status --show-token >/dev/null 2>&1
}

function create_tag_if_not_exists() {
local tag=$1
local list=$(tag_list)

if ! echo "$list" | grep -q "^$tag$"; then
git tag $tag
echo "Tag $tag created successfully"
else
echo "Tag $tag already exists"
fi
}

function create_release_if_not_exists() {
local tag=$1
if ! gh release view $tag >/dev/null 2>&1; then
gh release create $tag --title $version --generate-notes
echo "Release $tag created successfully"
else
echo "Release $tag already exists"
fi
}

if git_installed; then
if inside_git_repo; then
if gh_cli_installed; then
if ! gh_cli_logined; then
echo "You are not logged in to GitHub CLI. Please login using 'gh auth login'"
exit 1
fi

if [ -z "$version" ]; then
version=$(new_tag $release_type)
fi

echo "New tag: $version"
read -p "Do you want to create this tag? (y/n) " -n 1 -r
echo ""

if [[ $REPLY =~ ^[Yy]$ ]]; then
create_tag_if_not_exists $version

git push origin $version
echo "Tag pushed successfully"

create_release_if_not_exists $version
else
echo "Tag creation aborted"
fi
else
echo "GitHub CLI is not installed. Please install it from https://cli.github.com"
fi
else
echo "Not inside a git repo"
fi
else
echo "Git is not installed"
fi
2 changes: 1 addition & 1 deletion src/lib/markdownParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function hasAnyImageOrVideo() {
const rawContent = github.context.payload.pull_request?.body ?? '';
const { repo, owner } = await repository.getRepositoryInfo();

return rawContent.includes(`https://github.com/${owner}/${repo}/assets/`);
return rawContent.includes('https://github.com/user-attachments');
}

async function missingImageOrVideo() {
Expand Down

0 comments on commit 6147ac6

Please sign in to comment.