PHP code example of conduit-ui / pr

1. Go to this page and download the library: Download conduit-ui/pr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

conduit-ui / pr example snippets


use ConduitUI\Pr\PullRequest;

// Approve and merge a PR
PullRequest::find('owner/repo', 123)
    ->approve('LGTM! Shipping it.')
    ->merge();

// Auto-merge all passing Dependabot PRs
PullRequest::query('owner/repo')
    ->author('dependabot[bot]')
    ->open()
    ->get()
    ->filter(fn($pr) => $pr->checksPass())
    ->each(fn($pr) => $pr->merge());

PullRequest::find('owner/repo', 456)
    ->approve('Great work! Tests look good.');

PullRequest::find('owner/repo', 789)
    ->requestChanges('Please add tests for the new feature.');

PullRequest::find('owner/repo', 101)
    ->comment('Consider extracting this logic into a separate class.');

PullRequest::find('owner/repo', 202)
    ->addInlineComment(
        path: 'src/Service.php',
        line: 42,
        comment: 'This could cause a race condition'
    );

$pr = PullRequest::find('owner/repo', 123);
$pr->merge(); // Merge commit (default)

$pr->merge(strategy: 'squash'); // Squash and merge
$pr->merge(strategy: 'rebase'); // Rebase and merge

$pr = PullRequest::find('owner/repo', 123);

if ($pr->checksPass() && $pr->approved()) {
    $pr->merge();
}

// Close without merging
$pr->close();

// Reopen a closed PR
$pr->reopen();

PullRequest::query('owner/repo')
    ->state('open')
    ->get();

PullRequest::query('owner/repo')
    ->author('username')
    ->get();

PullRequest::query('owner/repo')
    ->labels(['ready-to-merge', 'hotfix'])
    ->get();

PullRequest::query('owner/repo')
    ->sort('created', 'desc')
    ->get();

// All open PRs
PullRequest::query('owner/repo')->open()->get();

// All closed PRs
PullRequest::query('owner/repo')->closed()->get();

// All merged PRs
PullRequest::query('owner/repo')->merged()->get();

// Run this on a schedule (every 15 minutes)
PullRequest::query('owner/repo')
    ->author('dependabot[bot]')
    ->open()
    ->get()
    ->filter(fn($pr) => $pr->checksPass())
    ->filter(fn($pr) => $pr->title->contains(['patch', 'minor']))
    ->each(function($pr) {
        $pr->approve('Auto-approving passing dependency update');
        $pr->merge(strategy: 'squash');
    });

// Block merge if not approved by 2+ reviewers
$pr = PullRequest::find('owner/repo', 123);

if ($pr->approvals()->count() < 2) {
    $pr->comment('⚠️ This PR 

// Add "shipped" label to all merged PRs from this week
PullRequest::query('owner/repo')
    ->merged()
    ->since(now()->startOfWeek())
    ->get()
    ->each(fn($pr) => $pr->addLabels(['shipped']));

// Auto-merge hotfixes that pass CI
PullRequest::query('owner/repo')
    ->label('hotfix')
    ->open()
    ->get()
    ->filter(fn($pr) => $pr->checksPass())
    ->each(function($pr) {
        $pr->approve('Hotfix approved via automation');
        $pr->merge(strategy: 'squash');
    });

use ConduitUI\Pr\PullRequest;

$pr = PullRequest::find('owner/repo', 123);
$prs = PullRequest::query('owner/repo')->open()->get();

use ConduitUI\Pr\PullRequestManager;

$manager = new PullRequestManager('owner/repo');
$pr = $manager->find(123);
$prs = $manager->query()->open()->get();

$pr->id;              // int
$pr->number;          // int
$pr->title;           // string
$pr->state;           // 'open' | 'closed' | 'merged'
$pr->author;          // User object
$pr->reviewers;       // Collection of User objects
$pr->labels;          // Collection of Label objects
$pr->headBranch;      // string
$pr->baseBranch;      // string
$pr->mergeable;       // bool
$pr->createdAt;       // Carbon instance
$pr->updatedAt;       // Carbon instance
$pr->mergedAt;        // ?Carbon instance
$pr->checksPass();    // bool - All CI checks passing
$pr->approved();      // bool - Has approvals
$pr->approvals();     // Collection of Review objects
bash
php artisan vendor:publish --tag="pr-config"