Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
D docker-containers
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Public
  • docker-containers
  • Wiki
  • code refactoring

code refactoring · Changes

Page history
feat: add the refactoring code authored Nov 04, 2020 by Yogesh Hegde's avatar Yogesh Hegde
Hide whitespace changes
Inline Side-by-side
Showing with 164 additions and 0 deletions
+164 -0
  • code-refactoring.md code-refactoring.md +164 -0
  • No files found.
code-refactoring.md
View page @ 46b7f48b
......@@ -12,3 +12,167 @@ At then end the goal is to achieve simpler, cleaner, faster and code compliant c
### Refactoring practical
Goal of the module is to fix problems with the existing code and refactor the code.
The module provides 2 sample example code in 2 coding languages (CPP & Python)
1. Get the workspace for refactoring
- Download the ready to use workspace for refactoring - https://gitlab.iotiot.in/newbies/pre-office-office/refactoring-workspace/-/archive/master/refactoring-workspace-master.zip
- Unzip the `refactoring-workspace-master.zip`
- Open VScode.
- Press `Ctrl` + `Shift` + `p` in VScode. A bar will open up at the top.
- Search for `Remote-Containers`
![remote-containers](upload/refactor1.png)
- Click on "Remote-Containers: Open Folder in Containers".
- In the pop up Window, Navigate to Downloads --> refactoring-workspace-master
- Click on Open.
- Vscode will take some time to start up the container, once done
- Open up terminal by Pressing `Ctrl` + `j`.
![remote-containers](upload/Selection_032.png)
- That is it done you have successfully opened up the workspace. Now you can get to refactoring.
2. Fork the refactoring repository.
- Go to link - https://gitlab.iotiot.in/newbies/pre-office-office/refactoring-trial
- Click on Fork.
![fork](upload/Selection_023.png)
- Select your username in the next window.
- The repo will fork and you should be directed to your own copy of the original repository.
3. Clone the repository.
- Copy Repository URL from the
![clone](upload/Selection_024.png)
- Go to your VScode which has the refactoring workspace opened.
![remote-containers](upload/Selection_032.png)
- Type `git clone {your-repository-URL-here}` in the terminal. (for ex: `git clone https://gitlab.iotiot.in/yh42/refactoring-trial`)
![clone2](upload/Selection_025.png)
- Type `cd refactoring-trial` and open up the repository.
4. Choose a coding language Python or CPP to refactor code. (choose the language that you are most comfortable with)
- Type `cd codestyle/{language}` (for ex: `cd codestyle/cpp`)
5. Choose any one sample code to refactor. There are 2 sample codes
1. yhatzee-game - [Click here to read code doc](https://gitlab.iotiot.in/newbies/pre-office-office/refactoring-trial/blob/master/codestyle/cpp/yhatzee-game/README.md)
2. tennis - [Click here to read code doc](https://gitlab.iotiot.in/newbies/pre-office-office/refactoring-trial/blob/master/codestyle/cpp/tennis/README.md)
6. Check coding style of the codes
- For python
<details>
<summary> Click to see your steps! </summary>
- Make sure that you are in the folder codestyle/python, Check by running command `pwd`
- Type `cd {your-chosen-example}` in VScode terminal. (for ex: `cd tennis`)
- Run command
- For Tennis `pycodestyle tennis.py`
- For yhatzee-game `pycodestyle yahtzee.py`
- After running the command you will get a big list of errors in the coding style.
</details>
- For CPP
<details>
<summary> Click to see your steps! </summary>
- Make sure that you are in the folder codestyle/cpp, Check by running command `pwd`
- Type `cd {your-chosen-example}` in VScode terminal. (for ex: `cd tennis`)
- Run commands
```sh
mkdir build
cd build
cmake ../
make codestyle
```
- After running the command you will get a big list of errors in the coding style.
</details>
7. Make changes to the code
- For Python Example
<details>
<summary> Click to see your steps! </summary>
- Run command `pytest`
- You will see your refactored code get tested. If anything fails the test will report the failure.
</details>
- For CPP Example
<details>
<summary> Click to see your steps! </summary>
- For Tennis example, run commands
```sh
make
./tennis1_tests
```
- For yhatzee-game, run commands
```sh
make
./yahtzee_tests
```
- You will see your refactored code get tested. If anything fails the test will report the failure.
</details>
8. Test if your refactored code passes all the tests.
- For Python
<details>
<summary> Click to see your steps! </summary>
- Run command `pytest`
- You will see your refactored code get tested. If anything fails the test will report the failure.
</details>
- For CPP
<details>
<summary> Click to see your steps! </summary>
- For Tennis example, run commands
```sh
make
./tennis1_tests
```
- For yhatzee-game, run commands
```sh
make
./yahtzee_tests
```
- You will see your refactored code get tested. If anything fails the test will report the failure.
</details>
9. Repeat the steps 6, 7, 8 till all the code style errors are solved.
10. Submit the changes.
- Run commands
```sh
cd /home/shunya/refactoring-trial
git config --global user.name "{Your-name}"
#(for ex: `git config --global user.name "Yogesh Hegde"`)
git config --global user.email "{your-email-id}"
#(for ex: `git config --global user.email "yogesh@iotiot.in"`)
git add .
git commit -m "refactored code"
git push
```
![submit-cmd](upload/Selection_027.png)
11. See your code Build, Test and Deploy via CI/CD.
- Go to your repository (the one that you have forked), CI/CD --> Pipelines.
![pipleines](upload/Screenshot%20from%202020-11-03%2015-34-57.png)
- You can see Build, Test and Deploy devOps stages passing.
![stages](upload/Selection_028.png)
- Click on the `passed` to see all the individual stage summary.
![stages-1](upload/Selection_029.png)
12. Thats is it done, you have successfully Refactored your code and see it Built, Tested and Deployed via CI/CD.
Clone repository
  • Installing tools
  • Readme doc format
  • code refactoring
  • code style container
  • day0
  • devops practical
  • docusaurus
  • Home
  • install on mac
  • install tools ubuntu 16.04
  • install tools windows