Skip to content
Team WorkflowChapter 53 / 57Intermediate6 min read

Pull Requests & Code Review

Code review best practices aur achi pull request, chhota diff, template wali description, reviewer ki zimmedariyan aur review comments likhne ka tareeqa.

On this page

1. Yeh practice kya hai?

Pull request (PR) do kaam karta hai: bug ko production se pehle pakarna, aur team ko pata hona ke code mein kya badla aur kyun. Review gatekeeping nahi, doosri nazar hai.

2. Kyun zaroori hai?

2,000 lines ke PR ko koi sach mein review nahi karta, sirf scroll karta hai. Bina description ke reviewer ko andaza lagana parta hai ke code kya karna chahta tha, is liye woh sirf style par comment karta hai aur asli masla (missing auth check) nikal jata hai.

Kamzor PR processMazboot PR process
1,500 lines, teen kaam ek saath400 lines se kam, ek kaam
Description: fixed stuffKya, kyun, kaise test hua
Author khud merge bina reviewDoosre ka approval
CI red lekin mergeCI green ke bagair merge nahi
Comments ka jawab nahiHar comment ka jawab, chahe sirf done
Review hafton pendingEk working day ke andar

3. Kab follow karein?

LevelKitna zarooriKyun
Learning projectApne liye PR kholna aur description likhnaApna kaam explain karna seekhte hain
Production codePoora ruleHar merge production tak jata hai
Senior levelAcha reviewer banna, sensitive areas ki ownershipTeam ka quality bar aap se banta hai

4. Bura vs acha code

Bura PR description

bash
title: Updates
body: fixed some bugs and added the thing we discussed

Acha PR description

bash
title: block expired coupons at checkout

why
  expired coupons were still applied because the check used the server
  timezone, so customers in later timezones got a free extra day

what changed
  coupon expiry compared in utc in the coupon service
  checkout returns 422 with a clear message for expired coupons

how tested
  unit tests for the expiry helper around midnight utc
  endpoint tests: valid coupon, expired coupon (422), other store coupon (404)

task: link to the tracker ticket
screenshots: error message on checkout attached

Review comments: bura vs acha

bash
hmm, not sure about this, maybe we could think about another approach?
bash
check the order belongs to the current store before updating

  const order = await orders.findForStore(id, user.storeId)

Acha comment ek line mein batata hai kya karna hai, aur fix code ke saath deta hai.

Farq kya hai?

CheezBuraAcha
TitleUpdatesKya badla, ek line
WhyGayabBug ki wajah aur asar
TestingGayabExact cases
CommentMubham sawalWazeh hidayat aur code

5. Kaise apply karein?

Author ke liye

PR kholne se merge tak
Kaam ek PR ke size ka rakhein (400 lines se kam)
Template ka har section bharein, jo lagu nahi woh delete
Task ya ticket link karein
CI green: typecheck, lint, build, tests, secret scan
Doosre ka approval
Har comment ka jawab
Author squash merge kare

Bara kaam ho to PRs ka stack banayein: pehle migration, phir service aur tests, phir UI.

Reviewer ke liye

KaamKyun
Diff se pehle description parheinPata ho code kya karna chahta hai, "why" na ho to poochein
Har mutation par authorization check dhoondheinSab se khatarnak bug yahi hai
Har query par tenant scopingEk org ka data doosri ko na dikhe
Naye env vars .env.example mein?Agla deploy na toote
Naye endpoints ke tests?Definition of done
Block sirf correctness, security ya standard ke liyePasand napasand par nahi
Ek working day ke andar review, warna kisi aur ko deinPR intezar mein na sare

Auth, billing, migrations aur deploy scripts ko chhoone wale PR par us area ke owner ka approval lena behtar hai.

6. Exceptions aur common mistakes

Kab rule nahi lagta: typo ya ek line docs fix ke liye poora template zaroori nahi, lekin PR aur green CI phir bhi. AI review tools madadgar hain, lekin woh insaan ke approval ki jagah nahi lete.

Merge style par teams mukhtalif hain: kuch squash merge (ek PR ek commit) pasand karti hain, kuch merge commits ya rebase taake har chhota commit main par rahe. Squash ke saath PR ka title hi final commit message banta hai, is liye title saaf hona chahiye.

Galati: LGTM bina parhe

Why? Approval ka matlab hai aap ne zimmedari li, aur missing auth check aap ke naam par bhi hai.

Behtar: Kam az kam mutations, queries aur tests parhein, ya saaf kahein ke review nahi kar sakte.

Galati: Ek PR mein feature, refactor aur upgrade

Why? Reviewer kisi ek par focus nahi kar pata aur bug chhup jata hai.

Behtar: Har kaam ka alag PR, refactor pehle aur behaviour change baad mein.

Galati: Comment ko ignore karke merge

Why? Reviewer ko nahi pata ke baat suni gayi ya nahi, aur trust kam hota hai.

Behtar: Har comment ka jawab dein: fix kiya, ya kyun nahi kiya.

7. Pehle aur baad mein kya seekhein?

Final quick revision

CheckHaan?
PR 400 lines se kam, ek kaam
Template bhara: why, what, how tested
Task linked
CI green
Doosre ka approval
Har comment ka jawab
Reviewer ne auth aur tenant scoping dekhi