Skip to main content

Get a Contribution

This page describes how to get a contribution. The returned object contains all details about the contribution, the most important one is the status and who reviewed it.

tip

Tip: the generation fields represent how many times the contribution has been modified by either the user or a moderator.

warning

The contribution object does not describe the changes the contribution is proposing. To retrieve those information use Get Contribution Changes instead.

Sample

The following sample shows how to get a contribution.

Replace [CONTRIBUTION-NAME] with a valid contribution name you are authorized to see.

tip

Tip: do not forget to replace CLIENT-ID and CLIENT-SECRET with valid IAM Service Account client credentials.

package main

import (
"context"
"log"

"golang.org/x/oauth2/clientcredentials"

"google.golang.org/api/option"

gapic "github.com/animeapis/api-go-client/knowledge/v1alpha1"
knowledge "github.com/animeapis/go-genproto/knowledge/v1alpha1"
)

var (
ContributionName = "[CONTRIBUTION-NAME]"

ClientID = "[CLIENT-ID]"
ClientSecret = "[CLIENT-SECRET]"
)

var (
TokenURL = "https://accounts.animeshon.com/o/oauth2/token"
Endpoint = "knowledge.animeapis.com:443"
)

func main() {
ctx := context.Background()

config := &clientcredentials.Config{
ClientID: ClientID,
ClientSecret: ClientSecret,
TokenURL: TokenURL,
}

options := []option.ClientOption{
option.WithEndpoint(Endpoint),
option.WithTokenSource(config.TokenSource(ctx)),
}

client, err := gapic.NewClient(ctx, options...)
if err != nil {
log.Fatalf("NewClient: %s", err)
}

request := &knowledge.GetContributionRequest{
Name: ContributionName,
}

contribution, err := client.GetContribution(ctx, request)
if nil != err {
log.Fatalf("GetContribution: %s", err)
}

log.Println("---------------------------------------------------------")
log.Printf("name : %s", contribution.GetName())
log.Printf("displayName : %s", contribution.GetDisplayName())
log.Printf("state : %s", contribution.GetState())
log.Printf("reviewer : %s", contribution.GetReviewer())
log.Printf("generation : %d", contribution.GetGeneration())
}
View on GitHub