generated from freeCodeCamp/template
-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
add an action to remove trailing spaces when opening a PR #551
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Format PR Files | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
paths: | ||
- '**/*.md' # Trigger workflow only when .md files are modified in the PR | ||
|
||
jobs: | ||
whitespace: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Git config | ||
run: | | ||
git config --global user.name "miyaliu666" | ||
git config --global user.email "[email protected]" | ||
|
||
- name: Remove trailing whitespaces from Markdown files | ||
run: | | ||
echo "Target branch: ${{ github.event.pull_request.base.ref }}" | ||
echo "Head branch: ${{ github.event.pull_request.head.ref }}" | ||
|
||
# Get the base commit between the target branch (main) and the source branch (HEAD) | ||
base_branch="${{ github.event.pull_request.base.ref }}" | ||
head_branch="${{ github.event.pull_request.head.ref }}" | ||
|
||
git fetch origin $base_branch | ||
git fetch origin $head_branch | ||
|
||
base_commit=$(git merge-base origin/$base_branch origin/$head_branch) | ||
echo "Base commit: $base_commit" | ||
|
||
# Get the changed files in the current PR | ||
echo "Checking changes in PR..." | ||
files=$(git diff --name-only $base_commit origin/$head_branch) | ||
echo "Changed files: $files" | ||
|
||
# Filter out .md files | ||
file=$(echo "$files" | grep '\.md$') | ||
echo "Filtered .md file: $file" | ||
|
||
if [ -n "$file" ]; then | ||
echo "Processing file: $file" | ||
# Remove trailing spaces from each line in the file | ||
sed -i 's/ $//g' "$file" | ||
# Switch to the source branch and push the changes | ||
git checkout $head_branch | ||
git add "$file" | ||
git commit -m "Remove trailing spaces from $file" | ||
git push origin $head_branch | ||
else | ||
echo "No .md files found or no changes to commit." | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettier can fix all kinds of formatting issues including the tail spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment, @TechQuery.
I think we eventually want to utilize Prettier for formatting, but what we are currently trying to do is a little different. We want to intentionally make changes to every lines just to make it easier for proofreaders to comment on any lines in PRs.
There might be a better solution, but let's try this way first.