MCPcopy Index your code
hub / github.com/OpenListTeam/OpenList / signCommit

Function signCommit

drivers/github/util.go:133–167  ·  view source on GitHub ↗
(m *map[string]interface{}, entity *openpgp.Entity)

Source from the content-addressed store, hash-verified

131}
132
133func signCommit(m *map[string]interface{}, entity *openpgp.Entity) (string, error) {
134 var commit strings.Builder
135 commit.WriteString(fmt.Sprintf("tree %s\n", (*m)["tree"].(string)))
136 parents := (*m)["parents"].([]string)
137 for _, p := range parents {
138 commit.WriteString(fmt.Sprintf("parent %s\n", p))
139 }
140 now := time.Now()
141 _, offset := now.Zone()
142 hour := offset / 3600
143 author := (*m)["author"].(map[string]string)
144 commit.WriteString(fmt.Sprintf("author %s <%s> %d %+03d00\n", author["name"], author["email"], now.Unix(), hour))
145 author["date"] = now.Format(time.RFC3339)
146 committer := (*m)["committer"].(map[string]string)
147 commit.WriteString(fmt.Sprintf("committer %s <%s> %d %+03d00\n", committer["name"], committer["email"], now.Unix(), hour))
148 committer["date"] = now.Format(time.RFC3339)
149 commit.WriteString(fmt.Sprintf("\n%s", (*m)["message"].(string)))
150 data := commit.String()
151
152 var sigBuffer bytes.Buffer
153 err := openpgp.DetachSign(&sigBuffer, entity, strings.NewReader(data), nil)
154 if err != nil {
155 return "", fmt.Errorf("signing failed: %v", err)
156 }
157 var armoredSig bytes.Buffer
158 armorWriter, err := armor.Encode(&armoredSig, "PGP SIGNATURE", nil)
159 if err != nil {
160 return "", err
161 }
162 if _, err = utils.CopyWithBuffer(armorWriter, &sigBuffer); err != nil {
163 return "", err
164 }
165 _ = armorWriter.Close()
166 return armoredSig.String(), nil
167}

Callers 1

commitMethod · 0.85

Calls 5

CopyWithBufferFunction · 0.92
NowMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
EncodeMethod · 0.45

Tested by

no test coverage detected