...

Source file src/github.com/xanzy/go-gitlab/resource_weight_events.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Matthias Simon
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"time"
    23  )
    24  
    25  // ResourceWeightEventsService handles communication with the event related
    26  // methods of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/resource_weight_events.html
    29  type ResourceWeightEventsService struct {
    30  	client *Client
    31  }
    32  
    33  // WeightEvent represents a resource weight event.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/resource_weight_events.html
    36  type WeightEvent struct {
    37  	ID           int            `json:"id"`
    38  	User         *BasicUser     `json:"user"`
    39  	CreatedAt    *time.Time     `json:"created_at"`
    40  	ResourceType string         `json:"resource_type"`
    41  	ResourceID   int            `json:"resource_id"`
    42  	State        EventTypeValue `json:"state"`
    43  	IssueID      int            `json:"issue_id"`
    44  	Weight       int            `json:"weight"`
    45  }
    46  
    47  // ListWeightEventsOptions represents the options for all resource weight events
    48  // list methods.
    49  //
    50  // GitLab API docs:
    51  // https://docs.gitlab.com/ee/api/resource_weight_events.html#list-project-issue-weight-events
    52  type ListWeightEventsOptions struct {
    53  	ListOptions
    54  }
    55  
    56  // ListIssueWeightEvents retrieves resource weight events for the specified
    57  // project and issue.
    58  //
    59  // GitLab API docs:
    60  // https://docs.gitlab.com/ee/api/resource_weight_events.html#list-project-issue-weight-events
    61  func (s *ResourceWeightEventsService) ListIssueWeightEvents(pid interface{}, issue int, opt *ListWeightEventsOptions, options ...RequestOptionFunc) ([]*WeightEvent, *Response, error) {
    62  	project, err := parseID(pid)
    63  	if err != nil {
    64  		return nil, nil, err
    65  	}
    66  	u := fmt.Sprintf("projects/%s/issues/%d/resource_weight_events", PathEscape(project), issue)
    67  
    68  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    69  	if err != nil {
    70  		return nil, nil, err
    71  	}
    72  
    73  	var wes []*WeightEvent
    74  	resp, err := s.client.Do(req, &wes)
    75  	if err != nil {
    76  		return nil, resp, err
    77  	}
    78  
    79  	return wes, resp, nil
    80  }
    81  

View as plain text