github.com/diggerhq/digger/libs@v0.0.0-20240604170430-9d61cdf01cc5/orchestrator/github/mocks.go (about)

     1  package github
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/diggerhq/digger/libs/orchestrator"
     6  )
     7  
     8  type MockCiService struct {
     9  	CommentsPerPr map[int][]*orchestrator.Comment
    10  }
    11  
    12  func (t MockCiService) GetUserTeams(organisation string, user string) ([]string, error) {
    13  	return nil, nil
    14  }
    15  
    16  func (t MockCiService) GetApprovals(prNumber int) ([]string, error) {
    17  	return []string{}, nil
    18  }
    19  
    20  func (t MockCiService) GetChangedFiles(prNumber int) ([]string, error) {
    21  	return nil, nil
    22  }
    23  func (t MockCiService) PublishComment(prNumber int, comment string) (*orchestrator.Comment, error) {
    24  
    25  	latestId := 0
    26  
    27  	for _, comments := range t.CommentsPerPr {
    28  		for _, c := range comments {
    29  			if c.Id.(int) > latestId {
    30  				latestId = c.Id.(int)
    31  			}
    32  		}
    33  	}
    34  
    35  	t.CommentsPerPr[prNumber] = append(t.CommentsPerPr[prNumber], &orchestrator.Comment{Id: latestId + 1, Body: &comment})
    36  
    37  	return &orchestrator.Comment{Id: int64(latestId)}, nil
    38  }
    39  
    40  func (t MockCiService) ListIssues() ([]*orchestrator.Issue, error) {
    41  	return nil, fmt.Errorf("implement me")
    42  }
    43  
    44  func (t MockCiService) PublishIssue(title string, body string) (int64, error) {
    45  	return 0, fmt.Errorf("implement me")
    46  }
    47  
    48  func (t MockCiService) SetStatus(prNumber int, status string, statusContext string) error {
    49  	return nil
    50  }
    51  
    52  func (t MockCiService) GetCombinedPullRequestStatus(prNumber int) (string, error) {
    53  	return "", nil
    54  }
    55  
    56  func (t MockCiService) MergePullRequest(prNumber int) error {
    57  	return nil
    58  }
    59  
    60  func (t MockCiService) IsMergeable(prNumber int) (bool, error) {
    61  	return true, nil
    62  }
    63  
    64  func (t MockCiService) IsMerged(prNumber int) (bool, error) {
    65  	return false, nil
    66  }
    67  
    68  func (t MockCiService) DownloadLatestPlans(prNumber int) (string, error) {
    69  	return "", nil
    70  }
    71  
    72  func (t MockCiService) IsClosed(prNumber int) (bool, error) {
    73  	return false, nil
    74  }
    75  
    76  func (t MockCiService) GetComments(prNumber int) ([]orchestrator.Comment, error) {
    77  	comments := []orchestrator.Comment{}
    78  	for _, c := range t.CommentsPerPr[prNumber] {
    79  		comments = append(comments, *c)
    80  	}
    81  	return comments, nil
    82  }
    83  
    84  func (t MockCiService) EditComment(prNumber int, commentId interface{}, comment string) error {
    85  	for _, comments := range t.CommentsPerPr {
    86  		for _, c := range comments {
    87  			if c.Id == commentId {
    88  				c.Body = &comment
    89  				return nil
    90  			}
    91  		}
    92  	}
    93  	return nil
    94  }
    95  
    96  func (t MockCiService) CreateCommentReaction(id interface{}, reaction string) error {
    97  	// TODO implement me
    98  	return nil
    99  }
   100  
   101  func (t MockCiService) GetBranchName(prNumber int) (string, string, error) {
   102  	return "", "", nil
   103  }
   104  
   105  func (svc MockCiService) SetOutput(prNumber int, key string, value string) error {
   106  	//TODO implement me
   107  	return nil
   108  }