Skip to content

fix: safely replace description placeholder in janitor run #116

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LtdSauce
Copy link
Contributor

@LtdSauce LtdSauce commented May 2, 2025

Before this commit a (single-)quote or the pipe symbol in the description would make the janitor fail to replace the description placeholder as those made the sed statement malformed.

A first fix is to store the value of the description in a variable and pass that to the sed statement. This eliminates the problems of quotes and variable expansion due to $ signs. The variable had to be passed as a real variable instead of using githubs variable replacement as with that the shell would still see the quotes and parse them.

The second thing to fix is to escape any occurences of the pipe symbol in the description as that is what the sed command uses as its delimiter. The escaping has to be done by adding a literal \ to the description so during the sed command the | will stay in place. While doing this it became clear that also the \ has to be escaped as it would otherwise vanish after the sed run. Thus this is done prior to escaping the pipe symbol in order to not also mess with the introduced \ in that command.

To verify it is working the test step gained a new variable that is injected if the it is no new repo. With this at least it is checked that the description can contain the special characters. One thing to note though is that setting the test variable and extracting the actual description need to look alike so we can be sure the actual retrieval will not fail.

fixes #114

Before this commit a (single-)quote or the pipe symbol in the description would
make the janitor fail to replace the description placeholder as those made the
sed statement malformed.

A first fix is to store the value of the description in a variable and
pass that to the sed statement. This eliminates the problems of quotes
and variable expansion due to $ signs. The variable had to be passed
as a real variable instead of using githubs variable replacement
as with that the shell would still see the quotes and parse them.

The second thing to fix is to escape any occurences of the pipe symbol
in the description as that is what the sed command uses as its
delimiter. The escaping has to be done by adding a literal \ to
the description so during the sed command the | will stay in place.
While doing this it became clear that also the \ has to be escaped
as it would otherwise vanish after the sed run. Thus this is done
prior to escaping the pipe symbol in order to not also mess with
the introduced \ in that command.

To verify it is working the test step gained a new variable that
is injected if the it is no new repo. With this at least it is
checked that the description can contain the special characters.
One thing to note though is that setting the test variable and
extracting the actual description need to look alike so we can
be sure the actual retrieval will not fail.
Copy link

codecov bot commented May 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 20.50%. Comparing base (1015c6b) to head (e12e9e4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #116   +/-   ##
=======================================
  Coverage   20.50%   20.50%           
=======================================
  Files           5        5           
  Lines         239      239           
  Branches      112      109    -3     
=======================================
  Hits           49       49           
- Misses        179      181    +2     
+ Partials       11        9    -2     
Flag Coverage Δ
Linux 17.64% <ø> (ø)
Windows 21.02% <ø> (ø)
macOS 18.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template Janitor job fails if repo description contains quote character
1 participant