MCPcopy
hub / github.com/AlistGo/alist / signCommit

Function signCommit

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

Source from the content-addressed store, hash-verified

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

Callers 1

commitMethod · 0.85

Calls 4

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

Tested by

no test coverage detected