Exploring Sourcery Code Methods: A Developer's Guide

By Amr

Explore sourcery code methods to enhance your programming skills and streamline your development process effectively.

Estimated reading time: 4 minutes

Edit on Github

Here’s a structured overview of GitHub best practices for source code control, including commit hygiene, pull request management, changelog documentation, automation strategies, and integrating AI into these workflows:


🗃️ 1. 

Branch Management & Pull Requests (PRs)

Use separate branches for features, bug fixes, minor updates, and major releases:

Branch type Naming example Use case PR requirements
Main (protected) main Production-ready code Peer-reviewed & CI-tested
Feature Branch feature/login-ui New functionality or feature Clear feature description & tests
Bugfix Branch bugfix/login-issue Fixing known issues Bug reference and reproduction steps
Hotfix Branch hotfix/security-patch Urgent fixes, typically for prod Minimal changes, urgent review
Release Branch release/v2.1.0 Staging releases Reviewed, tagged, and documented

📋 

Pull Request Documentation

Every PR must include:

  • Description: Purpose of changes.

  • Issue Reference: Link relevant GitHub issues (bug, feature request).

  • Test Plan: How changes were tested.

  • Screenshots/Demos: Optional but recommended for UI/UX.

  • Review Checklist: Clearly define what reviewers should verify.

Example PR Template:

## Description
Briefly describe the changes made and the context.

## Fixes
Resolves issue #123

## Type of Change
- [ ] Feature
- [x] Bug Fix
- [ ] Minor Update
- [ ] Major Update

## Test Plan
1. Step one
2. Step two (expected result)

## Screenshots
Attach images or videos if necessary.

## Reviewer Checklist
- [ ] Code reviewed
- [ ] Tests passed
- [ ] Documentation updated

📝 2. 

Commit Hygiene & Best Practices

Each commit should:

  • Atomicity: Address one logical change per commit.

  • Descriptive Message:

    • Format: [type]: Short description

      • feat: feature

      • fix: bug fix

      • docs: documentation

      • refactor: code refactor

      • test: tests

      • chore: maintenance tasks (build scripts, deps)

  • Commit Message Structure:

[type]: Brief, imperative summary (50 chars)

Detailed explanation if needed, wrapping at 72 chars.
- Bullet points for clarity
- Issue references (e.g., Fixes #456)

Example Commit:

feat: Add login authentication via OAuth

Implements OAuth authentication for Google login.
- Redirects after successful login
- Includes unit tests

Fixes #78

📖 3. 

Changelog & Documentation

Maintain a structured CHANGELOG.md using conventional commits or semantic versioning.

Example CHANGELOG.md format:

## [1.2.0] - YYYY-MM-DD
### Added
- OAuth login (Feature #78)

### Fixed
- Login bug preventing session creation (Bug #123)

## [1.1.2] - YYYY-MM-DD
### Fixed
- Minor CSS issues in header (Bug #102)

Use tools to automate changelog generation, such as:


🤖 4. 

Automation with GitHub Actions

Automate as much as possible with GitHub Actions:

  • Linting & Testing: Automatically run linters, unit tests, integration tests on each PR.

  • PR Checks & Validations: Automate code reviews, dependency checks, and security vulnerability scans.

  • Automatic Releases: Auto-generate changelogs, increment version numbers, create GitHub releases/tags.

Example GitHub Actions Workflow (.github/workflows/main.yml):

name: CI/CD Pipeline

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - run: |
        pip install -r requirements.txt
        pytest tests/

  release:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: release-drafter/release-drafter@v6
      with:
        config-name: release-drafter.yml
      env:
        GITHUB_TOKEN: $

🧠 5. 

AI-Assisted Automation

Integrating AI can help automate repetitive tasks:

  • Auto-generating Changelogs: AI summarizes commit changes into clear release notes.

  • Code Reviews: AI-assisted reviews flag common issues or suggest improvements.

  • Documentation Generation: AI fills in gaps in documentation based on codebase changes.

  • Pull Request Summaries: AI creates concise, descriptive summaries for PRs.

Recommended Tools for AI Integration:

  • GitHub Copilot: Code generation, comments, reviews.

  • OpenAI API via GitHub Actions: Automated documentation, changelog summaries.

  • CodeQL (built into GitHub): AI-driven security analysis.

Example AI-based PR summary with OpenAI API (pseudo workflow):

  1. Triggered by PR creation.

  2. AI fetches commit diff.

  3. AI summarizes changes into a PR comment automatically.


🛠️ 

Complete Best Practice Workflow Summary

Stage Activity Recommended Practice / Automation
Coding Write atomic, descriptive commits Use conventional commit messages
Branching Create branches for distinct tasks Feature/bugfix/hotfix naming conventions
Pull Requests Thorough documentation Use templates with required information
Code Reviews Peer review + automated checks Linting, testing, security (via GitHub Actions)
Merging Merge after reviews and tests Squash merge for clarity (optional)
Release Automate release/tagging Semantic versioning and auto-generated changelogs
Documentation Automatically update documentation Use GitHub Actions & AI assistance

🎯 

  • GitHub Copilot

  • Release Drafter

  • OpenAI API integrated via GitHub Actions

  • Dependabot (dependency management automation)


Adopting these practices ensures your GitHub workflow is scalable, transparent, maintainable, and efficient—leveraging automation and AI to reduce manual overhead and human error.