Jump to content

User:YuviPanda/G2G

From mediawiki.org

Tentative name for a set of scripts that make Gerrit/GitHub interoperability possible (phab:T37497). This project is being developed at https://github.com/yuvipanda/SuchABot

All actual code modifications happen on GitHub, discussion happens on GitHub *and* Gerrit (synced 2 way), and final merging happens in Gerrit. It does not require that new contributors who wish to contribute via GitHub have a Gerrit account. Also does not require git-review.

As of 2013 it is enabled in the following repositories:

Workflow

[edit]

It is a bot that does the following:

  1. Watch for new pull requests in GitHub.
  2. When a new PR comes in, opens an equivalent Gerrit patchset, and leaves a comment on the GitHub PR.
    1. If there are multiple commits in the GH PR, they are all squashed into one.
    2. Commit message is combination of title, description & commit messages of all commits in PR.
    3. There's a link in the commit message to original PR.
    4. Author information is preserved (hopefully only one person pushes to a PR).
    5. Committer is the bot account.
  3. Whenever there is a comment on either GH or Gerrit, it is synced to the other.
    1. Inline comments go to their appropriate inline places.
    2. PR comments become patchset comments, and vice versa.
    3. V, C changes in Gerrit leave a text comment on GH.
  4. When new commits are added to a PR, the appropriate Gerrit patchset is modified.
  5. When a Gerrit Patchset is modified, the appropriate PR doesn't get anything added. We might even decide to invalidate the PR when this happens. Reason being in Gerrit everything is squashed so there's no way to just push a single new commit to the PR.
  6. Abandon / Merge in Gerrit does the same in GitHub, but *not* vice versa.

Implementation

[edit]

This should be implemented as a bunch of python scripts running on labs. A special purpose account should be created on both GH and Gerrit for the bot. It'll probably just use polling, but GH's post receive webhooks might be useful here. Gerrit might have a similar mechanism too - we could perhaps integrate this the same way Jenkins is integrated.

Alternative is to write a Gerrit plugin, but it has the disadvantage of being GWT/Java, and the advantage of producing simpler looking boxes when represented by an UML diagram.

An approach that combines both might also be possible. Need more research to find the simplest approach that could possibly work.

Modules

[edit]
  1. GH PR modifications watcher
  2. GH PR -> Gerrit Patchset committer
  3. Gerrit Patchset comments -> GH PR comments
  4. Gerrit Inline comments -> GH Inline Comments
  5. GH PR comments -> Gerrit Patchset comments
  6. GH Inline Comments -> Gerrit Inline comments
  7. Gerrit Abandon / Merge -> GH close pull request

Planning

[edit]

Trying to get all of this done at once will end in disaster, so let's get it done bit by bit

Iteration 1

[edit]
  1. Create gerrit bot account, GH bot account, setup keys on labs Yes Done
  2. GH PR watcher Yes Done
  3. GH PR -> Gerrit Patchset Commiter (only initial request - manual trigger) Yes Done

By the end of this, the bot can pick up brand new PRs and create equivalent Gerrit patchsets. It's okay to have this manually trigger.

Iteration 2

[edit]
  1. GH PR -> Gerrit Patchset Updater (when new commit is added - automatic trigger) Yes Done
  2. Automatic trigger for initial GH PR -> Gerrit Patchset committer Yes Done

New commits added to a GH PR should automatically update patchset.

Iteration 3

[edit]
  1. Gerrit Patchset Comment -> GH PR Comment (Automatic) Yes Done
  2. Gerrit Merge / Abandon -> GH PR Merge / Abandon Yes Done

This brings partial one way discussions sync from Gerrit to GitHub. Also automatic.

Iteration 4

[edit]
  1. Gerrit Inline Comment -> GH inline Comment

This completes the Gerrit -> GH discussion sync.

Iteration 5

[edit]
  1. GH PR Comments -> Gerrit Patchset comments
  2. GH Close -> Gerrit abandon

Iteration 6

[edit]
  1. GH Inline Comments -> Gerrit Inline Comments

This completes GH <-> Gerrit two way sync

Timeline

[edit]

Absolutely no clue. I don't think the iterations are equal length either - they are merely logically grouped bundles of work. I hope to get at least a good chunk of this done before end of April 2013, however - I'll be afk all of May.