rb-gateway post commit APIs

Review Request #6972 — Created Feb. 22, 2015 and submitted

Information

rb-gateway
master
db50a09...

Reviewers

This is to add support for the post commit UI that Review Board currently has. In order for Review Board Gateway hosted repositories to support this UI, rb-gateway must provide APIs for getting branches, getting commits, and getting an individual commit.

The URL for get branches is located at /branches and it requires a repository as the parameter. The returned JSON looks as follows:
[
{
"name": master,
"id": "1b6f00c0fe975dd12251431ed2ea561e0acc6d44"
}
]

The URL for get commits is located at /commits and it requries a repository as the parameter, as well as the branch id. An optional start commit parameter can be provided to retrieve the commits beginning at the start commit. The returned JSON looks as follows:
[
{
"author": "John Doe",
"id": "1b6f00c0fe975dd12251431ed2ea561e0acc6d44",
"date": "2015-06-27T05:51:39-07:00",
"message": "Add README.md",
"parent_id": "bfdde95432b3af879af969bd2377dc3e55ee46e6"
}
]

The URL for get commit is located at /commit and it requries a repository as the parameter, as well as the commit id. The returned JSON looks as follows:
{
"author": "John Doe",
"id": "1b6f00c0fe975dd12251431ed2ea561e0acc6d44",
"date": "2015-06-27T05:51:39-07:00",
"message": "Add README.md",
"parent_id": "bfdde95432b3af879af969bd2377dc3e55ee46e6",
"diff": "diff --git a/test b/test
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..044f599c9a720fe1a7d02e694a8dab492cbda8f0 100644
--- a/test
+++ b/test
@@ -1 +1,3 @@
test
+
+test"
}

The following are URLs ran through my browser and self rb-gateway, git repository test environment. I've listed the JSON that is returned.

http://localhost:8002/branches?repo=testrepo
[{"name":"im_a_branch","id":"83904e6acb60e7ec0dcaae6c09a579ab44d0cf38"},{"name":"master","id":"bfdde95432b3af879af969bd2377dc3e55ee46e6"}]

http://localhost:8002/commits?repo=testrepo&branch=bfdde95432b3af879af969bd2377dc3e55ee46e6
[{"author":"Jessica Yuen","id":"bfdde95432b3af879af969bd2377dc3e55ee46e6","date":"2015-02-13 22:34:01 -0700 -0700","message":"Modified test\n","parent_id":"304c53c163aedfd0c0e0933776f09c24b87f5944"}, ... ]

http://localhost:8002/commits?repo=testrepo&branch=bfdde95432b3af879af969bd2377dc3e55ee46e6&start=fa1330719893098ae397356e8125c2aa45b49221
[{"author":"Jessica Yuen","id":"fa1330719893098ae397356e8125c2aa45b49221","date":"2015-02-12 16:01:48 -0700 -0700","message":"Removing all files in preparation for demo\n","parent_id":"9a3e0527e8decfabc12bbd9b75d0a683ef8320e2"}]

For comparison, git log returns the following, notice that the start commit is omitted in the above request:
commit bfdde95432b3af879af969bd2377dc3e55ee46e6
Author: Jessica Yuen jyuen@ualberta.ca
Date: Fri Feb 13 22:34:01 2015 -0700

Modified test

commit 304c53c163aedfd0c0e0933776f09c24b87f5944
Author: Jessica Yuen jyuen@ualberta.ca
Date: Fri Feb 13 22:32:42 2015 -0700

Added .reviewboardrc

commit fa1330719893098ae397356e8125c2aa45b49221
Author: Jessica Yuen jyuen@ualberta.ca
Date: Thu Feb 12 16:01:48 2015 -0700

Removing all files in preparation for demo

http://localhost:8002/commit?repo=testrepo&commit=304c53c163aedfd0c0e0933776f09c24b87f5944
{"author":"Jessica Yuen","id":"304c53c163aedfd0c0e0933776f09c24b87f5944","date":"2015-02-13 22:32:42 -0700 -0700","message":"Added .reviewboardrc\n","parent_id":"fa1330719893098ae397356e8125c2aa45b49221","diff":"diff --git a/.reviewboardrc b/.reviewboardrc\nindex e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..044f599c9a720fe1a7d02e694a8dab492cbda8f0 100644\n--- a/.reviewboardrc\n+++ b/.reviewboardrc\n@@ -0,0 +1,2 @@\n+REVIEWBOARD_URL = 'http://localhost:8080/'\n+REPOSITORY = 'test-repo1'\n"}

Description From Last Updated

For get_commits, I don't think we'd want to include the diff, since it could end up being a huge amount …

daviddavid

This isn't quite right. Because of the way the git frontend works, we want to use start if it's available, …

daviddavid

We need to make sure that this includes full indexes.

daviddavid

This should probably be in an else clause, right?

daviddavid

This should probably be in an else clause, right?

daviddavid

It would be nice to have better error codes here. If the commit isn't found, then this should return 404. …

daviddavid

This should probably be in an else clause, right?

daviddavid

Can we reformat this to put one item per line? gitCommit := GitCommit{ commit.Author().Name, commit.Id().String(), commit.Author().When.String(), commit.Message(), parent }

daviddavid

Can we reformat this to put one item per line? gitCommit := GitCommit{ commit.Author().Name, commit.Id().String(), commit.Author().When.String(), commit.Message(), parent, diff }

daviddavid

sorry again by why 10 branches?

brenniebrennie

Is there any particular reason the maximum size is 20? Should this be a constant somewhere?

brenniebrennie

Again, this probably should be a constant.

brenniebrennie
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
JY
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
david
  1. 
      
  2. git_repository.go (Diff revision 3)
     
     
     
     
     
     
     
     
     
    Show all issues

    For get_commits, I don't think we'd want to include the diff, since it could end up being a huge amount of data to transmit every time /r/new/ is opened up.

  3. git_repository.go (Diff revision 3)
     
     
     
     
     
     
     
    Show all issues

    This isn't quite right. Because of the way the git frontend works, we want to use start if it's available, and branch if it's not. This should basically be the result of git log start. Of note is that start is the latest commit to log, and we go back in history from there. Subsequent calls will use the

    I think what we want to do is something like this:

    if len(start) != 0 {
            revWalk.PushHead(start)
    } else {
            revWalk.PushHead(branch)
    }
    

    We'd then list out one "page" of commits (probably 30?) and return that.

  4. git_repository.go (Diff revision 3)
     
     
    Show all issues

    We need to make sure that this includes full indexes.

  5. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
david
  1. 
      
  2. routes.go (Diff revision 5)
     
     
     
    Show all issues

    This should probably be in an else clause, right?

  3. routes.go (Diff revision 5)
     
     
     
    Show all issues

    This should probably be in an else clause, right?

  4. routes.go (Diff revision 5)
     
     
     
     
    Show all issues

    It would be nice to have better error codes here. If the commit isn't found, then this should return 404. If it was but there was some other error, then http.StatusInternalServerError is probably more appropriate than StatusBadRequest.

  5. routes.go (Diff revision 5)
     
     
     
    Show all issues

    This should probably be in an else clause, right?

  6. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
david
  1. 
      
  2. git_repository.go (Diff revision 6)
     
     
     
    Show all issues

    Can we reformat this to put one item per line?

    gitCommit := GitCommit{
            commit.Author().Name,
            commit.Id().String(),
            commit.Author().When.String(),
            commit.Message(),
            parent
    }
    
  3. git_repository.go (Diff revision 6)
     
     
     
    Show all issues

    Can we reformat this to put one item per line?

    gitCommit := GitCommit{
            commit.Author().Name,
            commit.Id().String(),
            commit.Author().When.String(),
            commit.Message(),
            parent,
            diff
    }
    
  4. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
david
  1. This looks good to me. Are there any other changes you had planned for this before it gets pushed?

    1. Nope, I've tested all the API calls on RB's side and they work well for what RB provides and needs. Functionalities shouldn't need to be changed.

  2. 
      
brennie
  1. 
      
  2. git_repository.go (Diff revision 7)
     
     
    Show all issues

    Is there any particular reason the maximum size is 20? Should this be a constant somewhere?

  3. git_repository.go (Diff revision 7)
     
     
    Show all issues

    Again, this probably should be a constant.

  4. 
      
brennie
  1. 
      
  2. git_repository.go (Diff revision 7)
     
     
    Show all issues

    sorry again by why 10 branches?

  3. 
      
JY
reviewbot
  1. Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
    
    Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        routes.go
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
JY
Review request changed
Status:
Completed
Change Summary:
Pushed to master (72a587e)