|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>GitGitGadget - contributing git.git patches via GitHub PRs</title> |
| 5 | + <link rel="stylesheet" href="main.css"> |
| 6 | + </head> |
| 7 | + <body> |
| 8 | + <div class="banner"> |
| 9 | + <table style="width: 100%"> |
| 10 | + <tbody> |
| 11 | + <tr> |
| 12 | + <td> |
| 13 | + <img src="images/gitgitgadget-explanation.png" alt="An arrow from git logo to an envelop with git logo. The arrow is labelled by famous Inspector Gadget hat." style="height: 150px;"> |
| 14 | + </td> |
| 15 | + <td> |
| 16 | + <big>GitGitGadget</big> |
| 17 | + <br /> |
| 18 | + Contributing git.git patches via GitHub PRs |
| 19 | + <br /> |
| 20 | + <small>... one iteration at a time...</small> |
| 21 | + </td> |
| 22 | + </tr> |
| 23 | + </tbody> |
| 24 | + </table> |
| 25 | + </div> |
| 26 | + |
| 27 | + <div class="block"> |
| 28 | + <h1 id="how-does-gitgitgadget-process-user-comments-on-prs">How does GitGitGadget process user comments on PRs?</h1> |
| 29 | +<p>GitGitGadget is implemented as a GitHub App (with the very imaginative name <a href="https://github.com/apps/gitgitgadget">"GitGitGadget"</a>), which means that a webhook is called on certain events, such as new PR comments on PRs (e.g. <code>issue_comment</code>).</p> |
| 30 | +<p>In GitGitGadget's case, this webhook is implemented as an Azure Function: <a href="https://github.com/gitgitgadget/gitgitgadget/tree/master/azure-function">https://github.com/gitgitgadget/gitgitgadget/tree/master/azure-function</a></p> |
| 31 | +<p>Apart from validating that the payload really originated from GitHub, the Azure Function performs a rudimentary check whether the comment (if it was triggered by a comment) contains a command that GitGitGadget should act on, and depending on that check triggers the Azure Pipeline <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=3">GitGitGadget PR Handler</a>.</p> |
| 32 | +<p>The <code>push</code> event (and also the <code>pull_request</code> event) is not actually handled by the Azure Function. It is handled via the Azure Pipeline being configured as "Pull request validation". That also allows it to be shown in the Checks tab of the PR.</p> |
| 33 | +<p>You can see the difference on <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=3">the summary page of the GitGitGadget PR Handler pipeline</a>: the <code>push</code>-triggered builds are labeled as "Pull request build", and the <code>issue_comment</code> ones as "Manual build" (because they are triggered using a Personal Access Token, also known as "PAT").</p> |
| 34 | +<p>Depending how the Azure Pipeline was triggered, it calls <a href="https://github.com/gitgitgadget/gitgitgadget/blob/master/script/misc-helper.ts"><code>misc-helper.ts</code></a> with the <code>handle-pr-comment</code> or with the <code>handle-pr-push</code> parameter, respectively. More precisely, the pipeline has 4 steps:</p> |
| 35 | +<ol> |
| 36 | +<li>Use Node 10.x</li> |
| 37 | +<li>Pull GitGitGadget, run npm, essentially:<pre><code class="language-sh">test -d .git || git init || exit 1 |
| 38 | + |
| 39 | +git rev-parse HEAD >.git/PRE_FETCH_HEAD && |
| 40 | +git fetch https://github.com/gitgitgadget/gitgitgadget master || |
| 41 | +exit 1 |
| 42 | + |
| 43 | +[... commented-out dirty tricks to use PRs' patches early ...] |
| 44 | +git reset --hard FETCH_HEAD || |
| 45 | +exit 1 |
| 46 | + |
| 47 | +# If nothing was pulled, we already built it |
| 48 | +test "$(git rev-parse HEAD)" != "$(cat .git/PRE_FETCH_HEAD)" || |
| 49 | +exit 0 |
| 50 | + |
| 51 | +npm install && |
| 52 | +npm run build || |
| 53 | +exit 1 |
| 54 | +</code></pre> |
| 55 | +</li> |
| 56 | +<li>Obtain GitHub Token:<pre><code class="language-sh">GIT_CONFIG_PARAMETERS="$GIT_CONFIG_PARAMETERS $EXTRA_CONFIG" |
| 57 | +node build/script/misc-helper.js set-app-token && |
| 58 | +git config gitgitgadget.publishRemote \ |
| 59 | + https://x-access-token:$(git config gitgitgadget.githubToken)@github.com/gitgitgadget/git |
| 60 | +</code></pre> |
| 61 | +(The <code>EXTRA_CONFIG</code> is necessary because it contains a value that is configured via a secret pipeline variable.)</li> |
| 62 | +<li>Handle PR (Comment or Push):<pre><code class="language-sh">GIT_CONFIG_PARAMETERS="$GIT_CONFIG_PARAMETERS $EXTRA_CONFIG" |
| 63 | +set -x |
| 64 | +if test "$(pr.comment.id)" -lt 0 |
| 65 | +then |
| 66 | + case "$BUILD_SOURCEBRANCH" in |
| 67 | + refs/pull/[1-9]*/head|refs/pull/[1-9]*/merge) |
| 68 | + branchname=${BUILD_SOURCEBRANCH#refs/pull/} |
| 69 | + prnumber=${branchname%/*} |
| 70 | + ;; |
| 71 | + *) echo "Invalid source branch: $BUILD_SOURCEBRANCH">&2; exit 1;; |
| 72 | + esac |
| 73 | + node build/script/misc-helper.js handle-pr-push "$prnumber" |
| 74 | +else |
| 75 | + node build/script/misc-helper.js handle-pr-comment "$(pr.comment.id)" |
| 76 | +fi |
| 77 | +</code></pre> |
| 78 | +(The <code>pr.comment.id</code> pipeline variable is set when queuing the build via the Azure Function that is registered as a webhook, that's how we can discern between this mode vs push.)</li> |
| 79 | +</ol> |
| 80 | +<p>The pipeline variable <code>GIT_CONFIG_PARAMETERS </code> (which is pre-set as an environment variable in the scripts, interpreted by Git in the same way as <code>git -c <key>=<value> </code> would be) is defined as <code>'user.name=GitGitGadget' ' [email protected]' 'gitgitgadget.workDir=$(Agent.HomeDirectory)/../git-worktree' </code>, i.e. it configures GitGitGadget as committer and it asks GitGitGadget to fetch the commits and notes to the directory <code>git-worktree/ </code> that is located next to the Azure Pipeline build agent's own directory, which assumes that the agent is running in a suitable VM and its files are installed into the home directory of the account running the agent. </p> |
| 81 | +<p>Ideally, this definition (even if it is very small compared to other pipeline definitions I maintain) would be tracked in a Git repository, but since we want this to be a CI build (so that it neatly shows those Checks in the PR page), the pipeline is already associated with gitgitgadget/git (even if the pipeline is configured not to "sync the source", i.e. it does not check out the code pushed to the PR), and we cannot simply add GitGitGadget's Azure Pipelines' definitions to <code>master</code> because that is mirrored verbatim from git/git.</p> |
| 82 | +<h1 id="mirroring-replies-from-the-git-mailing-list-to-gitgitgadgets-prs">Mirroring replies from the Git mailing list to GitGitGadget's PRs</h1> |
| 83 | +<p>This is performed by the <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=5">Mirror Git List to GitGitGadget's PRs</a> pipeline. Its tasks look very similar to the ones of the GitGitGadget PR Handler pipeline described <a href="#how-does-gitgitgadget-process-user-comments-on-prs">above</a>, but it is triggered by updates to the <code>master</code> branch of the Git mailing list archive at <a href="https://public-inbox.org/git">https://public-inbox.org/git</a> and calls <code>misc-helper.js handle-new-mails</code>instead of the <code>handle-pr-comment</code>/<code>handle-pr-push</code> commands.</p> |
| 84 | +<h1 id="update-pr-labels-and-mentioning-whenwhere-the-patches-were-integrated">Update PR labels and mentioning when/where the patches were integrated</h1> |
| 85 | +<p>The PRs labels are updated, and the comments that document how the corresponding branch is called and when the patches were integrated and into which branch(es), and the PRs are closed when the patches hit <code>master</code> and/or <code>maint</code> by the <a href="https://dev.azure.com/gitgitgadget/git/_build/index?definitionId=2">Update GitGitGadget's PRs</a> pipeline. Its tasks look very similar to the GitGitGadget PR Handler pipeline described <a href="#how-does-gitgitgadget-process-user-comments-on-prs">above</a>, but it is triggered by updates to the branches <code>pu</code>, <code>next</code>, <code>master</code> and <code>maint</code> at <a href="https://github.com/git/git">https://github.com/git/git</a>, and it calls <code>misc-helper.ts update-open-prs</code>, <code>misc-helper.ts update-commit-mappings</code> and <code>misc-helper.ts handle-open-prs</code> instead of the <code>handle-pr-comment</code>/<code>handle-pr-push</code> commands.</p> |
| 86 | +<h1 id="keeping-httpsgithubcomgitgitgadgetgit-up-to-date">Keeping <a href="https://github.com/gitgitgadget/git">https://github.com/gitgitgadget/git</a> up to date</h1> |
| 87 | +<p>The repository gitgitgadget/git is kept up to date by two Azure Pipelines: <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=8">Synchronize gitster.git to GitGitGadget</a> and <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=7">Synchronize git.git to GitGitGadget</a>.</p> |
| 88 | +<h2 id="why-synchronize-both-gitgit-and-gitstergit">Why synchronize both git/git <em>and</em> gitster/git?</h2> |
| 89 | +<h3 id="background">Background</h3> |
| 90 | +<p>The existence of the <code>git/git</code> -> <code>gitgitgadget/git</code> pipeline is probably obvious.</p> |
| 91 | +<p>The <code>gitster/git</code> repository contains the individual branches for code contributions, and the first reason why the corresponding pipeline was added is that <code>pu</code> had test failures all the time without any actionable information: it has been always unclear <em>which</em> of those patch series that made it into <code>pu</code> was responsible for the test failures. Now with the individual branches being mirrored into <code>gitgitgadget/git</code>, and obviously triggering <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=4">CI builds</a>, it is a lot easier to find the culprits.</p> |
| 92 | +<p>Of course, from time to time the <code>pu</code> failures are caused by unfortunate interactions of separate patch series' changes, in which case the CI builds of the individual branches may very well succeed but <code>pu</code> still causes failures, which is a very useful piece of information in and of itself.</p> |
| 93 | +<p>A secondary benefit of mirroring the <code>gitster/git</code> branches is that PRs at <code>gitgitgadget/git</code> can target more fine-grained base commits. I use this a lot, e.g. in my six "built-in add -i/-p" patch series which build on top of each other.</p> |
| 94 | +<p>While the pipeline that synchronizes with <code>gitster/git</code> is triggered by all updates to <code>refs/heads/*</code>, for technical reasons polling every 180 seconds, i.e. every three minutes, the pipeline that synchronizes with <code>git/git</code> is triggered immediately. </p> |
| 95 | +<h3 id="what-do-the-pipelines-do-exactly">What do the pipelines do, exactly?</h3> |
| 96 | +<p>The pipeline that mirrors gitster/git into gitgitgadget/git (the pipeline names cannot contain slashes, that's why the <code>/</code> was replaced by a <code>.</code>) has two tasks:</p> |
| 97 | +<ol> |
| 98 | +<li>Synchronize branch:<pre><code class="language-bash">case "$(Build.SourceBranch)" in |
| 99 | +refs/heads/*) |
| 100 | + refspec="+HEAD:$(Build.SourceBranch)" |
| 101 | + ;; |
| 102 | +refs/tags/*) |
| 103 | + refspec="$(Build.SourceBranch)" |
| 104 | + ;; |
| 105 | +*) |
| 106 | + echo "Cannot handle '$(Build.SourceBranch)'" >&2 |
| 107 | + exit 1 |
| 108 | + ;; |
| 109 | +esac |
| 110 | + |
| 111 | +git -c http."https://github.com/gitgitgadget/git".extraheader="Authorization: Basic $(gitgitgadget.push.token.base64)" \ |
| 112 | + push https://github.com/gitgitgadget/git "$refspec" |
| 113 | +</code></pre> |
| 114 | +</li> |
| 115 | +<li>Synchronize tags (if necessary):<pre><code class="language-bash">die () { |
| 116 | + echo "$*" >&2 |
| 117 | + exit 1 |
| 118 | +} |
| 119 | + |
| 120 | +for d in git gitgitgadget |
| 121 | +do |
| 122 | + git ls-remote --tags https://github.com/$d/git | grep -v '\^{}$' | sort >tags.$d || |
| 123 | + die "Could not enumerate tags in $d" |
| 124 | +done |
| 125 | + |
| 126 | +refspec="$(comm -23 tags.git tags.gitgitgadget | tr '\t' :)" || |
| 127 | +die "Could figure out missing tags" |
| 128 | + |
| 129 | +if test -z "$refspec" |
| 130 | +then |
| 131 | + echo "##vso[task.complete result=Skipped]No tags to synchronize!" |
| 132 | +else |
| 133 | + git -c http."https://github.com/gitgitgadget/git".extraheader="Authorization: Basic $(gitgitgadget.push.token.base64)" \ |
| 134 | + push https://github.com/gitgitgadget/git $refspec |
| 135 | +fi |
| 136 | +</code></pre> |
| 137 | +</li> |
| 138 | +</ol> |
| 139 | +<p>That second task is necessary because there is currently no way to trigger non-YAML Azure Pipelines from tag updates. Of course this means that new tags are only synchronized together with branch updates, but in practice that's okay because the Git maintainer always pushes out the tags with corresponding branches.</p> |
| 140 | +<p>This task mirrors tags from the git/git repository, even if the pipeline purports to mirror <code>gitster/git</code> to <code>gitgitgadget/git</code>; This is a deliberate decision, to make sure that we only mirror the "official tags" from the authoritative repository.</p> |
| 141 | +<p>The two pipelines are identical except for these aspects:</p> |
| 142 | +<ul> |
| 143 | +<li>The <code>gitster/git</code> repository contains substantially more branches. The only <code>git/git</code> branch that is missing from <code>gitster/git</code> is <code>todo</code>, which <a href="https://github.com/gitgitgadget/gitgitgadget/issues/152">we might parse at some stage to provided concise excerpts from the "What's cooking" mails</a>.</li> |
| 144 | +<li>For technical reasons, the <code>git/git</code> pipeline does not need to poll.</li> |
| 145 | +</ul> |
| 146 | +<h3 id="git-guis-branches">Git GUI's branches</h3> |
| 147 | +<p>As GitGitGadget can also be used to contribute Git GUI patches and patch series, there is also the <a href="https://dev.azure.com/gitgitgadget/git/_build?definitionId=10">Synchronize git-gui.git (branches only) to GitGitGadget</a> pipeline. It mirrors the branches of Pratyush Yadav's repository (i.e. the current Git GUI maintainer's authoritative repository) into the <code>git-gui/*</code> namespace on <code>gitgitgadget/git</code>.</p> |
| 148 | + |
| 149 | + </div> |
| 150 | + </body> |
| 151 | +</html> |
0 commit comments