Coder Social home page Coder Social logo

Comments (3)

opalmer avatar opalmer commented on June 15, 2024

I have some code that does something similar to what you're trying to do that might help:

package main

import (
    "github.com/andygrunwald/go-gerrit"
)

func main() {
    client, err := gerrit.NewClient("", nil)
    if err != nil {
        panic(err)
    }

    changes, _, err := client.Changes.QueryChanges(
        &gerrit.QueryChangeOptions{
            QueryOptions: gerrit.QueryOptions{
                Query: []string{"(is:open OR is:merged) AND after:2016-09-20"}},
            ChangeOptions: gerrit.ChangeOptions{
                AdditionalFields: []string{
                    "DETAILED_LABELS",
                    "DETAILED_ACCOUNTS"}}})
    if err != nil {
        panic(err)
    }

    for _, change := range *changes {
        for _, label := range change.Labels.CodeReview.All {
            ...
        }
    }
}

I think all the info you're looking for is going to be somewhere under the change.Labels.CodeReview struct. Generally speaking go-gerrit does not really modify the structures returned from Gerrit so if Gerrit's documentation references the info you're looking for then it's usually a matter of either tuning the query or fixing where you look for the data. Failing that I usually try using curl to figure out what I'm missing and to understand the general data structure better.

Let me know if you have more questions of if I've missed something.

from go-gerrit.

perolausson avatar perolausson commented on June 15, 2024

I think you are misunderstanding me. The issue is that the information sent back for a "Query Changes" or "Get Change Detail" would normally not contain any information pertaining to approvals, if there are no approvals. In such cases the Json returned looks something like this:

....
"url": "https://lh5.googleusercontent.com/-83BEYip0k-E/AAAAAAAAAAI/AAAAAAAAAAA/rybERPNrtdM/s100-p/photo.jpg",
"height": 100
}
]
},
"labels": {
"Verified": {
"values": {
"-1": "Fails",
" 0": "No score",
"+1": "Verified"
},
"default_value": 0
},
"Code-Review": {
"values": {
"-2": "Do not submit",
"-1": "I would prefer that you didn\u0027t submit this",
" 0": "No score",
"+1": "Looks good to me, but someone else must approve",
"+2": "Looks good to me, approved"
},
"default_value": 0
}
},
"permitted_labels": {
"Code-Review": [
"-1",
" 0",
"+1"
]
},
"removable_reviewers": [],
"reviewers": {},
"reviewer_updates": [],
"messages": [
{
"id": "fc66fb4452cff31b138fbd67e3cef19953679a5b
....

I can see how you have through about this stuff. According to the documentation of the REST API a LabelInforecord should be returned and this would contain optional AccountInfoor ApprovalInforecords. But looking at AccountInfo _account_id is not set as optional, and therefore there will always be an AccountInforeturned by your API, even if there wasn't any returned by Gerrit.

So what I am saying is, I think you need to change the _account_idto be optional so that these fields will turn out to be nothing, if Gerrit didn't return anything. As it stands now, your API is basically saying that account_id 0 (admin?) has done some approvals when in fact they haven't.

And the follow on problem with the current state is that to figure out whether there actually is an approval I have to create an empty AccountInforecord and compare with that, since two structs with the same values return "equals" in Golang. But I'd rather not carry on like that and get the problem sorted at root cause.

from go-gerrit.

perolausson avatar perolausson commented on June 15, 2024

It's all ok from my point of view.

from go-gerrit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.