|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once "includes.php"; |
| 4 | + |
| 5 | +include "header.php"; |
| 6 | + |
| 7 | +ob_implicit_flush( true ); |
| 8 | + |
| 9 | +if ( $useOAuth && !$user ) { |
| 10 | + echo oauth_signin_prompt(); |
| 11 | + die(); |
| 12 | +} |
| 13 | + |
| 14 | +$wiki = $_GET['wiki']; |
| 15 | +$wikiData = get_wiki_data( $wiki ); |
| 16 | + |
| 17 | +if ( !can_delete( $wikiData['creator'] ) ) { |
| 18 | + die( '<p>You are not allowed to update this wiki.</p>' ); |
| 19 | +} |
| 20 | + |
| 21 | +echo '<div class="consoleLog">'; |
| 22 | + |
| 23 | +$patchesApplied = []; |
| 24 | +$linkedTasks = []; |
| 25 | +$commands = []; |
| 26 | + |
| 27 | +foreach ( $wikiData['patchList'] as $patch => $patchData ) { |
| 28 | + $r = $patchData['r']; |
| 29 | + $data = gerrit_query( "changes/?q=change:$r&o=LABELS&o=CURRENT_REVISION", true ); |
| 30 | + |
| 31 | + // get the info |
| 32 | + $repo = $data[0]['project']; |
| 33 | + $base = 'origin/' . $data[0]['branch']; |
| 34 | + $revision = $data[0]['current_revision']; |
| 35 | + $ref = $data[0]['revisions'][$revision]['ref']; |
| 36 | + $id = $data[0]['id']; |
| 37 | + |
| 38 | + $repos = get_repo_data(); |
| 39 | + if ( !isset( $repos[ $repo ] ) ) { |
| 40 | + $repo = htmlentities( $repo ); |
| 41 | + abandon( "Repository <em>$repo</em> not supported" ); |
| 42 | + } |
| 43 | + $path = $repos[ $repo ]; |
| 44 | + |
| 45 | + if ( |
| 46 | + $config[ 'requireVerified' ] && |
| 47 | + ( $data[0]['labels']['Verified']['approved']['_account_id'] ?? null ) !== 75 |
| 48 | + ) { |
| 49 | + // The patch doesn't have V+2, check if the uploader is trusted |
| 50 | + $uploaderId = $data[0]['revisions'][$revision]['uploader']['_account_id']; |
| 51 | + $uploader = gerrit_query( 'accounts/' . $uploaderId, true ); |
| 52 | + if ( !is_trusted_user( $uploader['email'] ) ) { |
| 53 | + abandon( "Patch must be approved (Verified+2) by jenkins-bot, or uploaded by a trusted user" ); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + $patchesApplied[] = $data[0]['_number'] . ',' . $data[0]['revisions'][$revision]['_number']; |
| 58 | + |
| 59 | + $r = $patchData['r']; |
| 60 | + $pOld = (int)$patchData['p']; |
| 61 | + $pNew = $data[0]['revisions'][$revision]['_number']; |
| 62 | + if ( $pNew > $pOld ) { |
| 63 | + echo "<strong>Updating change $r from patchset $pOld to $pNew.</strong>"; |
| 64 | + } else { |
| 65 | + echo "<strong>Change $r is already using the latest patchset ($pOld).</strong>"; |
| 66 | + continue; |
| 67 | + } |
| 68 | + |
| 69 | + $commands[] = [ |
| 70 | + [ |
| 71 | + 'PATCHDEMO' => __DIR__ . '/', |
| 72 | + 'REPO' => $path, |
| 73 | + 'REF' => $ref, |
| 74 | + 'BASE' => $base, |
| 75 | + 'HASH' => $revision, |
| 76 | + ], |
| 77 | + __DIR__ . '/applypatch.sh' |
| 78 | + ]; |
| 79 | + |
| 80 | + $relatedChanges = []; |
| 81 | + $relatedChanges[] = [ $data[0]['_number'], $data[0]['revisions'][$revision]['_number'] ]; |
| 82 | + |
| 83 | + // Look at all commits in this patch's tree for cross-repo dependencies to add |
| 84 | + $data = gerrit_query( "changes/$id/revisions/$revision/related", true ); |
| 85 | + // Ancestor commits only, not descendants |
| 86 | + $foundCurr = false; |
| 87 | + foreach ( $data['changes'] as $change ) { |
| 88 | + if ( $foundCurr ) { |
| 89 | + // Querying by change number is allegedly deprecated, but the /related API doesn't return the 'id' |
| 90 | + $relatedChanges[] = [ $change['_change_number'], $change['_revision_number'] ]; |
| 91 | + } |
| 92 | + $foundCurr = $foundCurr || $change['commit']['commit'] === $revision; |
| 93 | + } |
| 94 | + |
| 95 | + foreach ( $relatedChanges as [ $c, $r ] ) { |
| 96 | + $data = gerrit_query( "changes/$c/revisions/$r/commit", true ); |
| 97 | + |
| 98 | + preg_match_all( '/^Depends-On: (.+)$/m', $data['message'], $m ); |
| 99 | + foreach ( $m[1] as $changeid ) { |
| 100 | + if ( !in_array( $changeid, $patches, true ) ) { |
| 101 | + // The entry we add here will be processed by the topmost foreach |
| 102 | + $patches[] = $changeid; |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +$baseEnv = [ |
| 109 | + 'PATCHDEMO' => __DIR__, |
| 110 | + 'NAME' => $wiki, |
| 111 | +]; |
| 112 | + |
| 113 | +foreach ( $commands as $i => $command ) { |
| 114 | + $cmd = make_shell_command( $baseEnv + $command[0], $command[1] ); |
| 115 | + $error = shell_echo( $cmd ); |
| 116 | + if ( $error ) { |
| 117 | + abandon( "Could not update patch $i." ); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +// Update DB record with patches applied |
| 122 | +wiki_add_patches( $wiki, $patchesApplied ); |
| 123 | + |
| 124 | +echo "Done!"; |
| 125 | + |
| 126 | +echo '</div>'; |
0 commit comments