যদি আপনার কাছে GitHub-এ Gemini Code Assist-এর জন্য কাস্টম সেরা অনুশীলন বা রীতিনীতি থাকে যা আপনি চান যে তা পরীক্ষা করে দেখুন, তাহলে আপনি আপনার সংগ্রহস্থলের .gemini/ রুট ফোল্ডারে একটি styleguide.md ফাইল যোগ করতে পারেন। GitHub-এ Gemini Code Assist-এর এন্টারপ্রাইজ সংস্করণের ব্যবহারকারীরা একাধিক সংগ্রহস্থলে ব্যবহারের জন্য স্টাইল গাইড তথ্য যোগ করতে Google ক্লাউড কনসোল ব্যবহার করতে পারেন। উভয় ক্ষেত্রেই, স্টাইল গাইডটিকে একটি নিয়মিত মার্কডাউন ফাইল হিসেবে বিবেচনা করা হয় এবং GitHub-এ Gemini Code Assist-এর ব্যবহৃত স্ট্যান্ডার্ড প্রম্পটটি প্রসারিত করে। স্টাইল গাইড যোগ করার নির্দেশাবলীর জন্য, অ্যাড কনফিগারেশন ফাইল দেখুন।
স্ট্যান্ডার্ড কোড পর্যালোচনা প্যাটার্ন
যখন কাস্টম স্টাইল গাইড নির্দিষ্ট করা থাকে না, তখন জেমিনি কোড অ্যাসিস্ট তার কোড পর্যালোচনার উপর ফোকাস করে এমন ক্ষেত্রগুলির প্রধান বিভাগগুলি হল:
সঠিকতা : কোডটি যেমনটি ইচ্ছা তেমনভাবে কাজ করে তা নিশ্চিত করে এবং এজ কেসগুলি পরিচালনা করে, লজিক ত্রুটি, রেস শর্ত, বা ভুল API ব্যবহারের জন্য পরীক্ষা করে।
দক্ষতা : সম্ভাব্য কর্মক্ষমতা বাধা বা অপ্টিমাইজেশনের ক্ষেত্রগুলি চিহ্নিত করে, যেমন অতিরিক্ত লুপ, মেমরি লিক, অদক্ষ ডেটা স্ট্রাকচার, অপ্রয়োজনীয় গণনা, অতিরিক্ত লগিং এবং অদক্ষ স্ট্রিং ম্যানিপুলেশন।
রক্ষণাবেক্ষণযোগ্যতা : কোড পঠনযোগ্যতা, মডুলারিটি এবং ভাষার বাগধারা এবং সর্বোত্তম অনুশীলনের আনুগত্য মূল্যায়ন করে। ভেরিয়েবল, ফাংশন এবং ক্লাসের জন্য দুর্বল নামকরণ, মন্তব্য বা ডকুমেন্টেশনের অভাব, জটিল কোড, কোড ডুপ্লিকেশন, অসঙ্গত বিন্যাস এবং জাদু সংখ্যাগুলিকে লক্ষ্য করে।
নিরাপত্তা : ডেটা হ্যান্ডলিং বা ইনপুট যাচাইকরণের ক্ষেত্রে সম্ভাব্য দুর্বলতাগুলি চিহ্নিত করে, যেমন সংবেদনশীল ডেটার অনিরাপদ সঞ্চয়স্থান, ইনজেকশন আক্রমণ, অপর্যাপ্ত অ্যাক্সেস নিয়ন্ত্রণ, ক্রস-সাইট অনুরোধ জালিয়াতি (CSRF), এবং অনিরাপদ সরাসরি অবজেক্ট রেফারেন্স (IDOR)।
বিবিধ : পুল রিকোয়েস্ট পর্যালোচনা করার সময় অন্যান্য বিষয় বিবেচনা করা হয়, যেমন পরীক্ষা, কর্মক্ষমতা, স্কেলেবিলিটি, মডুলারিটি এবং পুনঃব্যবহারযোগ্যতা, এবং ত্রুটি লগিং এবং পর্যবেক্ষণ।
কনফিগারেশন ফাইল যোগ করুন
আপনার রিপোজিটরির রুটে অবস্থিত একটি .gemini/ ফোল্ডারে সমর্থিত কনফিগারেশন ফাইল যোগ করে আপনি জেমিনি কোড অ্যাসিস্ট আচরণ পরিবর্তন করতে পারেন। যদি আপনি .gemini/ ফোল্ডারে নিম্নলিখিত ফাইলগুলি যোগ করে থাকেন তবে জেমিনি কোড অ্যাসিস্ট নিম্নলিখিত ফাইলগুলি ব্যবহার করে:
config.yaml: এমন একটি ফাইল যাতে বিভিন্ন কনফিগারযোগ্য বৈশিষ্ট্য রয়েছে যা আপনি সক্ষম বা অক্ষম করতে পারেন, যার মধ্যে গ্লোব প্যাটার্ন ব্যবহার করে উপেক্ষা করার জন্য ফাইলগুলি নির্দিষ্ট করা অন্তর্ভুক্ত।styleguide.md: একটি মার্কডাউন ফাইল যা জেমিনি কোড অ্যাসিস্টকে কিছু নির্দিষ্ট নিয়ম নির্দেশ করে যা আপনি কোড পর্যালোচনা করার সময় এটি অনুসরণ করতে চান।
config.yaml উদাহরণ
নিম্নলিখিত কোড স্নিপেটটি একটি config.yaml ফাইলের উদাহরণ। এই উদাহরণে, প্রতিটি সম্পত্তি জেমিনি কোড অ্যাসিস্ট দ্বারা ব্যবহৃত ডিফল্ট মান অনুসারে সেট করা আছে। আপনি আপনার নিজস্ব config.yaml ফাইল তৈরি করতে এই স্নিপেটটি টেমপ্লেট হিসাবে ব্যবহার করতে পারেন:
have_fun: false
code_review:
disable: false
comment_severity_threshold: MEDIUM
max_review_comments: -1
pull_request_opened:
help: false
summary: true
code_review: true
include_drafts: true
ignore_patterns: []
config.yaml স্কিমা
নিম্নলিখিত কোড স্নিপেটটি config.yaml ফাইলের স্কিমা। এটি সমস্ত সম্ভাব্য কনফিগারেশন বিকল্প এবং তাদের গৃহীত মানগুলি সংজ্ঞায়িত করে:
$schema: "http://json-schema.org/draft-07/schema#" title: RepoConfig description: Configuration for Gemini Code Assist on a repository. All fields are optional and have default values. type: object properties: have_fun: type: boolean description: Enables fun features such as a poem in the initial pull request summary. Default: false. ignore_patterns: type: array items: type: string description: A list of glob patterns for files and directories that Gemini Code Assist should ignore. Files matching any pattern in this list will be skipped during interactions. Default: []. code_review: type: object description: Configuration for code reviews. All fields are optional and have default values. properties: disable: type: boolean description: Disables Gemini from acting on pull requests. Default: false. comment_severity_threshold: type: string enum: - LOW - MEDIUM - HIGH - CRITICAL description: The minimum severity of review comments to consider. Default: MEDIUM. max_review_comments: type: integer format: int64 description: The maximum number of review comments to consider. Use -1 for unlimited. Default: -1. pull_request_opened: type: object description: Configuration for pull request opened events. All fields are optional and have default values. properties: help: type: boolean description: Posts a help message on pull request open. Default: false. summary: type: boolean description: Posts a pull request summary on the pull request open. Default: true. code_review: type: boolean description: Posts a code review on pull request open. Default: true. include_drafts: type: boolean description: Enables agent functionality on draft pull requests. Default: true.
styleguide.md
styleguide.md ফাইলটিতে কোন নির্দিষ্ট স্কিমা নেই। বরং, এটি একটি স্বাভাবিক ভাষা বর্ণনা যা আপনি জেমিনি কোড অ্যাসিস্টকে এর কোড পর্যালোচনাগুলি কীভাবে গঠন করতে চান তার একটি বর্ণনা। নিম্নলিখিত কোড স্নিপেটটি একটি styleguide.md ফাইলের একটি উদাহরণ:
# Company X Python Style Guide
# Introduction
This style guide outlines the coding conventions for Python code developed at Company X.
It's based on PEP 8, but with some modifications to address specific needs and
preferences within our organization.
# Key Principles
* **Readability:** Code should be easy to understand for all team members.
* **Maintainability:** Code should be easy to modify and extend.
* **Consistency:** Adhering to a consistent style across all projects improves
collaboration and reduces errors.
* **Performance:** While readability is paramount, code should be efficient.
# Deviations from PEP 8
## Line Length
* **Maximum line length:** 100 characters (instead of PEP 8's 79).
* Modern screens allow for wider lines, improving code readability in many cases.
* Many common patterns in our codebase, like long strings or URLs, often exceed 79 characters.
## Indentation
* **Use 4 spaces per indentation level.** (PEP 8 recommendation)
## Imports
* **Group imports:**
* Standard library imports
* Related third party imports
* Local application/library specific imports
* **Absolute imports:** Always use absolute imports for clarity.
* **Import order within groups:** Sort alphabetically.
## Naming Conventions
* **Variables:** Use lowercase with underscores (snake_case): `user_name`, `total_count`
* **Constants:** Use uppercase with underscores: `MAX_VALUE`, `DATABASE_NAME`
* **Functions:** Use lowercase with underscores (snake_case): `calculate_total()`, `process_data()`
* **Classes:** Use CapWords (CamelCase): `UserManager`, `PaymentProcessor`
* **Modules:** Use lowercase with underscores (snake_case): `user_utils`, `payment_gateway`
## Docstrings
* **Use triple double quotes (`"""Docstring goes here."""`) for all docstrings.**
* **First line:** Concise summary of the object's purpose.
* **For complex functions/classes:** Include detailed descriptions of parameters, return values,
attributes, and exceptions.
* **Use Google style docstrings:** This helps with automated documentation generation.
```python
def my_function(param1, param2):
"""Single-line summary.
More detailed description, if necessary.
Args:
param1 (int): The first parameter.
param2 (str): The second parameter.
Returns:
bool: The return value. True for success, False otherwise.
Raises:
ValueError: If `param2` is invalid.
"""
# function body here
```
## Type Hints
* **Use type hints:** Type hints improve code readability and help catch errors early.
* **Follow PEP 484:** Use the standard type hinting syntax.
## Comments
* **Write clear and concise comments:** Explain the "why" behind the code, not just the "what".
* **Comment sparingly:** Well-written code should be self-documenting where possible.
* **Use complete sentences:** Start comments with a capital letter and use proper punctuation.
## Logging
* **Use a standard logging framework:** Company X uses the built-in `logging` module.
* **Log at appropriate levels:** DEBUG, INFO, WARNING, ERROR, CRITICAL
* **Provide context:** Include relevant information in log messages to aid debugging.
## Error Handling
* **Use specific exceptions:** Avoid using broad exceptions like `Exception`.
* **Handle exceptions gracefully:** Provide informative error messages and avoid crashing the program.
* **Use `try...except` blocks:** Isolate code that might raise exceptions.
# Tooling
* **Code formatter:** [Specify formatter, e.g., Black] - Enforces consistent formatting automatically.
* **Linter:** [Specify linter, e.g., Flake8, Pylint] - Identifies potential issues and style violations.
# Example
```python
"""Module for user authentication."""
import hashlib
import logging
import os
from companyx.db import user_database
LOGGER = logging.getLogger(__name__)
def hash_password(password: str) -> str:
"""Hashes a password using SHA-256.
Args:
password (str): The password to hash.
Returns:
str: The hashed password.
"""
salt = os.urandom(16)
salted_password = salt + password.encode('utf-8')
hashed_password = hashlib.sha256(salted_password).hexdigest()
return f"{salt.hex()}:{hashed_password}"
def authenticate_user(username: str, password: str) -> bool:
"""Authenticates a user against the database.
Args:
username (str): The user's username.
password (str): The user's password.
Returns:
bool: True if the user is authenticated, False otherwise.
"""
try:
user = user_database.get_user(username)
if user is None:
LOGGER.warning("Authentication failed: User not found - %s", username)
return False
stored_hash = user.password_hash
salt, hashed_password = stored_hash.split(':')
salted_password = bytes.fromhex(salt) + password.encode('utf-8')
calculated_hash = hashlib.sha256(salted_password).hexdigest()
if calculated_hash == hashed_password:
LOGGER.info("User authenticated successfully - %s", username)
return True
else:
LOGGER.warning("Authentication failed: Incorrect password - %s", username)
return False
except Exception as e:
LOGGER.error("An error occurred during authentication: %s", e)
return False
```
একাধিক সংগ্রহস্থল জুড়ে কনফিগারেশন ফাইল পরিচালনা করুন
যদি আপনার GitHub-এ Gemini Code Assist-এর এন্টারপ্রাইজ ভার্সন থাকে, তাহলে আপনি Google Cloud কনসোল ব্যবহার করে ডেভেলপার কানেক্ট সংযোগে লিঙ্ক করা সমস্ত রিপোজিটরিতে কনফিগারেশনের একটি সেট এবং একটি স্টাইল গাইড প্রয়োগ করতে পারেন।
মনে রাখবেন যে যদি এইভাবে পরিচালিত একটি সংগ্রহস্থলের নিজস্ব config.yaml অথবা styleguide.md থাকে, তাহলে নিম্নলিখিত আচরণটি ঘটে:
রিপোজিটরির
config.yamlসেটিংস Google ক্লাউড কনসোল সেটিংসকে ওভাররাইড করে।রিপোজিটরির
styleguide.mdগুগল ক্লাউড কনসোল স্টাইল গাইডের সাথে মিলিত।
নিম্নলিখিত ধাপগুলি দেখায় কিভাবে একাধিক সংগ্রহস্থল জুড়ে এক সেট কনফিগারেশন এবং একটি স্টাইল গাইড নিয়ন্ত্রণ করতে হয়। এই ধাপগুলি ধরে নেয় যে আপনি আগে এন্টারপ্রাইজ সংস্করণ সেট আপ করেছেন।
গুগল ক্লাউড কনসোলে, জেমিনি কোড অ্যাসিস্ট এজেন্টস এবং টুলস পৃষ্ঠায় যান।
এজেন্ট বিভাগে, কোড অ্যাসিস্ট সোর্স কোড ম্যানেজমেন্ট কার্ডটি খুঁজে বের করুন এবং অ্যাডভান্সড এ ক্লিক করুন।
এডিট কোড অ্যাসিস্ট সোর্স কোড ম্যানেজমেন্ট প্যানটি খোলে।
সংযোগ টেবিলে, আপনি যে সংযোগে কনফিগারেশন বা স্টাইল গাইড প্রয়োগ করতে চান তার নামে ক্লিক করুন।
সংযোগের বিশদ পৃষ্ঠাটি খোলে।
সেটিংস ট্যাবে, আপনি যে সেটিংস পরিবর্তন করতে চান তা আপডেট করুন।
স্টাইল গাইড ট্যাবে, এই সংযোগের সাথে যুক্ত রিপোজিটরিগুলি যে স্টাইল গাইডটি ব্যবহার করতে চান তা যোগ করুন।
সংরক্ষণ করুন ক্লিক করুন।