# PR Guideline
## Important Notes and Regulations
1. *It is strictly forbidden to APPROVE and COMPLETE your own PR that has not been code reviewed by other RD*
> If you violate it, you will be critized by the team!!
2. Before creating a PR, please remember to Rebase your own branch first
3. The following are the requirements to complete a PR based on repo
| **Repo** | **Approve** | **Other Conditions** |
| -------- | -------- | -------- |
| Lib | 1 person | without any Active,Pending |
| Master | 1 person | without any Active,Pending |
| Agent | 1 person | without any Active,Pending |
| DB-KR | 2 person | without any Active,Pending |
4. Not allowed to use **Set auto-complete**

5. Reviewers
* TD, Jenny, Jerry, Marc, Brogan, Yuwei (When adding a new PR, these members are assigned by default)
* If the members above are not able to help with Code Review, you may add other members as reviewer after PR has been created.
6. After 12:00 noon on the Monday of the weekly release, you are not allowed to create PR, and not allowed to click **Complete**
* PR can be created after 11:30 Tuesday of the release week. This is when the release candidate has been branched out
* If the PR is **Approved** before the release, please be careful to not press **Complete**
7. Please be sure to pass the following Reviewer check list before submitting the PR. Reviewer will pay attention to the following things:
* Solution is build-able
* Changes are working as expected
* Changes fulfill all the requirements specified in the TASK
* Variable names must be meaningful
* Appropriate comments are in place
* The response time for any API shall not exceed 2 seconds
## Request PR
## 1. How to add PR
1. Make sure you are on your feature branch
* klFeature/{YYYYMM}/{feature name}
* Push to origin
2. Create a Pull Request
* The bottom of the Repos sub-menu, click Pull Request -> Create a Pull Request

* Fill in Title -> you can use the trello title
* Fill in Description -> Trello TASK title and link

* **Add commit messages** can automatically list down all your commit items
* Press **Create**

3. Notify reviewer to do Code Review
* Sample request to group:
```
Code Review
Trello Task:
Master-資訊看板調整-PART2(焦點資訊)
(https://trello.com/c/zi5N9Wgs)
Lib
https://dev.azure.com/stackcore/PlatformKR/_git/Lib/pullrequest/258
Master
https://dev.azure.com/stackcore/PlatformKR/_git/Master/pullrequest/257
請相關人員協助,感謝
```
## 2. Fix feedback and update it to PR
1. Make changes on your current branch and do a SourceTree PUSH
2. On the PR page, if some feedbacks are not bugs, please leave a message so that reviewer can reconfirm and update the status

## 3. Merge conflict after creating PR

Go back to SourceTree and perform **REBASE**
1. [REBASE Guide](https://hackmd.io/Hy90AGsTs)
2. After performing rebase, delete the remote branch

3. PUSH the branch to remote again
4. On the PR page you will see that Merge conflicts will change to No merge conflicts

## 4. How to abandon a PR
If you have accidentally created a PR, you can Abandon it

After abandoning you can choose whether you want to delete the remote branch

## 5. How to add another reviewer to the PR
If all the added reviewers are busy, you may add another reviewer

## 6. Complete and delete branch
1. After completing and opt to Delete branch after merging, your branch still appears on your SourceTree

It is because you need to click **Fetch** and tick the **Prune tracking branches no longer present on remote(s)**

## 7. How to create a PR for Hotfix
Example: **Hotfix on release/3.74**
1. Create a new branch from release/3.74
2. klHotfix/3.74/{Brief description of the changes}
3. When creating a PR, by default, it will be from your branch to master, but we want to hotfix into release/3.74, so please adjust it to the correct target branch.

4. After it is completed, you may **cherry-pick** back to master
## Review PR
## 1. Problem with the code
1. After receiving PR, go to
**Azure DevOps -> Repos -> {Repo Name} -> Pull request**

2. Click **Files** tab to view all updated files, highlight the problematic part and click **+** to leave a message for the RD.
(Note: If it is not an issue, and you only want to leave a message, you may write it in the Overview section)
This is an example of a PR with 2 active comment that needs to be resolved

3. Review is completed, now you may change the status to **Wait for author**

## 2. Revision
1. When RD has come back with the changes, and you have confirmed that it is okay, you may click **Reply & Resolve**

2. When all comments are resolved, you may press **Approve**
3. If there are unresolved comments, PR cannot be completed