github.com/decred/politeia@v1.4.0/politeiawww/legacy/codetracker/github/database/cockroachdb/encoding.go (about)

     1  // Copyright (c) 2020 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package cockroachdb
     6  
     7  import "github.com/decred/politeia/politeiawww/legacy/codetracker/github/database"
     8  
     9  // EncodePullRequestReview encodes a database.PullRequestReview into a
    10  // cockroachdb PullRequestReview.
    11  func EncodePullRequestReview(dbPullRequestReview *database.PullRequestReview) PullRequestReview {
    12  	prReview := PullRequestReview{}
    13  	prReview.Author = dbPullRequestReview.Author
    14  	prReview.State = dbPullRequestReview.State
    15  	prReview.SubmittedAt = dbPullRequestReview.SubmittedAt
    16  	prReview.CommitID = dbPullRequestReview.CommitID
    17  	prReview.ID = dbPullRequestReview.ID
    18  	prReview.Number = dbPullRequestReview.Number
    19  	prReview.Repo = dbPullRequestReview.Repo
    20  	prReview.PullRequestURL = dbPullRequestReview.PullRequestURL
    21  
    22  	return prReview
    23  }
    24  
    25  // DecodePullRequestReview decodes a cockroachdb PullRequestReview into a
    26  // generic database.PullRequestReview
    27  func DecodePullRequestReview(prReview *PullRequestReview) *database.PullRequestReview {
    28  	return &database.PullRequestReview{
    29  		PullRequestURL: prReview.PullRequestURL,
    30  		Author:         prReview.Author,
    31  		State:          prReview.State,
    32  		SubmittedAt:    prReview.SubmittedAt,
    33  		CommitID:       prReview.CommitID,
    34  		ID:             prReview.ID,
    35  		Repo:           prReview.Repo,
    36  		Number:         prReview.Number,
    37  	}
    38  }
    39  
    40  // EncodePullRequest encodes a database.PullRequest into a cockroachdb
    41  // PullRequest.
    42  func EncodePullRequest(dbPullRequest *database.PullRequest) PullRequest {
    43  	return PullRequest{
    44  		ID:           dbPullRequest.ID,
    45  		URL:          dbPullRequest.URL,
    46  		Repo:         dbPullRequest.Repo,
    47  		Organization: dbPullRequest.Organization,
    48  		Number:       dbPullRequest.Number,
    49  		Author:       dbPullRequest.User,
    50  		State:        dbPullRequest.State,
    51  		UpdatedAt:    dbPullRequest.UpdatedAt,
    52  		ClosedAt:     dbPullRequest.ClosedAt,
    53  		MergedAt:     dbPullRequest.MergedAt,
    54  		Merged:       dbPullRequest.Merged,
    55  		Additions:    dbPullRequest.Additions,
    56  		Deletions:    dbPullRequest.Deletions,
    57  		MergedBy:     dbPullRequest.MergedBy,
    58  	}
    59  }
    60  
    61  // DecodePullRequest decodes a cockroachdb PullRequest into a generic
    62  // database.PullRequest
    63  func DecodePullRequest(pr *PullRequest) *database.PullRequest {
    64  	return &database.PullRequest{
    65  		ID:           pr.ID,
    66  		URL:          pr.URL,
    67  		Repo:         pr.Repo,
    68  		Organization: pr.Organization,
    69  		Number:       pr.Number,
    70  		User:         pr.Author,
    71  		State:        pr.State,
    72  		UpdatedAt:    pr.UpdatedAt,
    73  		ClosedAt:     pr.ClosedAt,
    74  		MergedAt:     pr.MergedAt,
    75  		Merged:       pr.Merged,
    76  		Additions:    pr.Additions,
    77  		Deletions:    pr.Deletions,
    78  		MergedBy:     pr.MergedBy,
    79  	}
    80  }
    81  
    82  func convertMatchingReviewsToDatabaseReviews(matching []MatchingReviews) []database.PullRequestReview {
    83  	reviews := make([]database.PullRequestReview, 0, len(matching))
    84  	for _, match := range matching {
    85  		reviews = append(reviews, database.PullRequestReview{
    86  			PullRequestURL: match.PullRequestURL,
    87  			ID:             match.ID,
    88  			Author:         match.Author,
    89  			State:          match.State,
    90  			Repo:           match.Repo,
    91  			SubmittedAt:    match.SubmittedAt,
    92  			Additions:      match.Additions,
    93  			Deletions:      match.Deletions,
    94  		})
    95  	}
    96  	return reviews
    97  }
    98  
    99  func encodeCommit(dbCommit *database.Commit) Commit {
   100  	return Commit{
   101  		SHA:          dbCommit.SHA,
   102  		URL:          dbCommit.URL,
   103  		Repo:         dbCommit.Repo,
   104  		Organization: dbCommit.Organization,
   105  		Message:      dbCommit.Message,
   106  		Date:         dbCommit.Date,
   107  		Author:       dbCommit.Author,
   108  		Committer:    dbCommit.Committer,
   109  		ParentSHA:    dbCommit.ParentSHA,
   110  		ParentURL:    dbCommit.ParentURL,
   111  		Additions:    dbCommit.Additions,
   112  		Deletions:    dbCommit.Deletions,
   113  	}
   114  }
   115  
   116  func decodeCommit(commit *Commit) *database.Commit {
   117  	return &database.Commit{
   118  		SHA:          commit.SHA,
   119  		URL:          commit.URL,
   120  		Repo:         commit.Repo,
   121  		Organization: commit.Organization,
   122  		Message:      commit.Message,
   123  		Date:         commit.Date,
   124  		Author:       commit.Author,
   125  		Committer:    commit.Committer,
   126  		ParentSHA:    commit.ParentSHA,
   127  		ParentURL:    commit.ParentURL,
   128  		Additions:    commit.Additions,
   129  		Deletions:    commit.Deletions,
   130  	}
   131  }