Skip to content
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

Improves Doc with sonar_rules_reused.md and passing it to tooling (sh scripts) #18

Conversation

Silicoman
Copy link
Contributor

Objectives

Gives a better comprehension of rules needed to be tag by "eco-design"

  • By listing them with a user friendly view (on Github) with markdown
  • Capitalize justifications about rules (with a tab)

Gives a one entry point to adding rules. (Not have to copy/paste new rules... risk to desync)

Execution

After testing script on my Ubuntu wsl, you wil got this log bash:

XXX@YYYY:/mnt/c/Dev/projets/ecoCode-common-5R/tools/rules_config$ ./install_tag.sh
--- DEBUG --- Read file ./SONAR_RULES_REUSED.md
--- DEBUG --- Extracting rules: css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck

--- DEBUG --- SONAR_TOKEN : zzzzzzzzzzzzzzzzzzzzzzzz
--- DEBUG --- SONAR_URL : http://localhost:9000
--- DEBUG --- RULES_KEYS : css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck
--- DEBUG --- TAG_ECOCONCEPTION : test1

*****  Checking SonarQube connection  *****
--- DEBUG --- SonarQube connection ok : 200

*****  Processing rule css:S4655  *****
Existing sysTags : []
Existing tags : []
  Tag test1 NOT FOUND in tags array nor in systags array : we will add it to rule 'css:S4655'
Execution of command : curl -u zzzzzzzzzzzzzzzzzzzz: -s -o /dev/null --request POST "http://localhost:9000/api/rules/update?key=css:S4655&tags=test1"
CALL to Sonar API to add tag

*****  Processing rule php:S2014  *****
Existing sysTags : []
Existing tags : []
  Tag test1 NOT FOUND in tags array nor in systags array : we will add it to rule 'php:S2014'
Execution of command : curl -u zzzzzzzzzzzzzzzzzzzzz: -s -o /dev/null --request POST "http://localhost:9000/api/rules/update?key=php:S2014&tags=test1"
CALL to Sonar API to add tag

*****  Processing rule Web:ItemTagNotWithinContainerTagCheck  *****
Existing sysTags : []
Existing tags : []
  Tag test1 NOT FOUND in tags array nor in systags array : we will add it to rule 'Web:ItemTagNotWithinContainerTagCheck'
Execution of command : curl -u zzzzzzzzzzzzzzzzzzz: -s -o /dev/null --request POST "http://localhost:9000/api/rules/update?key=Web:ItemTagNotWithinContainerTagCheck&tags=test1"
CALL to Sonar API to add tag

==> 3 rules updated

Will need a PR about "ecoconception" key word to switch to "ecodesign" like main repo.
I have also identify the script shell not failed in error if your token is not a user token.

@Silicoman
Copy link
Contributor Author

#17

@dedece35 dedece35 self-requested a review April 10, 2023 19:54
@dedece35 dedece35 added documentation Improvements or additions to documentation enhancement New feature or request 🏆 challenge 🏆 Work done during the ecoCode Challenge labels Apr 10, 2023
@dedece35 dedece35 linked an issue Apr 10, 2023 that may be closed by this pull request
done
done
} < $FILEPATH_SONAR_RULES_REUSED
debug "Extracting rules: ${rules_keys::-1} \n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on my local machine (MAC OSx), I have an error on lines with "::-1" string :
_core.sh: line 44: -1: substring expression < 0

thus my questions :

  • why not use ":-1" string value instead of "::-1" ?
  • why do you want to affect the default value 1 to rules_key ? for me no pb if no value in this variable. this use case is controlled => we will have an error like ERROR - config parameter 'RULES_KEYS' is NOT valid : it can't be empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concatenate each keys with a comma. The use of operator ::-1 is here to delete the last comma i have added.

I have tested for the experience:

  debug "Extracting rules: ${rules_keys::-1} \n"
  RULES_KEYS=${rules_keys:-1}
--- DEBUG --- Read file ./SONAR_RULES_REUSED.md
--- DEBUG --- Extracting rules: css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck

--- DEBUG --- SONAR_TOKEN : xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--- DEBUG --- SONAR_URL : http://localhost:9000
--- DEBUG --- RULES_KEYS : css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck,
--- DEBUG --- TAG_ECOCONCEPTION : test1

You will see the comma not deleted with :-1.
i find why you have a bug.... It's a function from bash 4.2 and you must have bash 3 if i'm looking the readme :D delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script
I will look for an older method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use ZSH to launch scripts ... here are my versions (ZSH but also BASH if you want)

~ ❯ zsh --version
zsh 5.9 (x86_64-apple-darwin22.0)
~ ❯ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin22)
Copyright (C) 2007 Free Software Foundation, Inc.
~

done
} < $FILEPATH_SONAR_RULES_REUSED
debug "Extracting rules: ${rules_keys::-1} \n"
RULES_KEYS=${rules_keys::-1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback as above

@dedece35 dedece35 added the 👀 👀 review done 👀 👀 review done - waiting for changes label Apr 10, 2023
@Silicoman
Copy link
Contributor Author

Silicoman commented Apr 10, 2023

@dedece35 , i replace with a sed function to got compatibility with your bash version.
Still for me, ok.

--- DEBUG --- Read file ./SONAR_RULES_REUSED.md
--- DEBUG --- Extracting rules: css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck

--- DEBUG --- SONAR_TOKEN : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--- DEBUG --- SONAR_URL : http://localhost:9000
--- DEBUG --- RULES_KEYS : css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck
--- DEBUG --- TAG_ECOCONCEPTION : test1

@dedece35 dedece35 merged commit 37f3233 into green-code-initiative:main Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏆 challenge 🏆 Work done during the ecoCode Challenge documentation Improvements or additions to documentation enhancement New feature or request 👀 👀 review done 👀 👀 review done - waiting for changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Doc versus Rules list inside _config.sh
2 participants