-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
745 lines (604 loc) · 21.7 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
package main
import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/fs"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"
"time"
"metascoop/apps"
"metascoop/file"
"metascoop/git"
"metascoop/md"
"github.com/google/go-github/v64/github"
"golang.org/x/oauth2"
)
func main() {
var (
reposFilePath = flag.String("rp", "repos.yaml", "Path to repos.yaml file")
repoDir = flag.String("rd", "fdroid/repo", "Path to fdroid \"repo\" directory")
accessToken = flag.String("pat", "", "GitHub personal access token")
commitMsgFile = flag.String("cm", "commit_message.tmp", "Path to the commit message file")
debugMode = flag.Bool("debug", false, "Debug mode won't run the fdroid command")
)
flag.Parse()
fmt.Println("::group::Initializing")
reposList, err := apps.ParseRepoFile(*reposFilePath)
if err != nil {
log.Fatalf("parsing given repos file: %s\n", err.Error())
}
var authenticatedClient *http.Client
if *accessToken != "" {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: *accessToken},
)
authenticatedClient = oauth2.NewClient(ctx, ts)
}
githubClient := github.NewClient(authenticatedClient)
fdroidIndexFilePath := filepath.Join(*repoDir, "index-v1.json")
// if the index file doesn't exist, we create it with the default values
if _, err := os.Stat(fdroidIndexFilePath); os.IsNotExist(err) {
defaultIndex := apps.RepoIndex{
Repo: map[string]interface{}{
"timestamp": time.Now().UnixMilli(),
"version": 20002,
"name": "My First F-Droid Repo Demo",
"icon": "icon.png",
"address": "",
"description": "This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/fdroid.",
},
Requests: map[string]interface{}{
"install": []string{},
"uninstall": []string{},
},
Apps: []map[string]interface{}{},
Packages: make(map[string][]apps.PackageInfo),
}
err := os.MkdirAll(filepath.Dir(fdroidIndexFilePath), 0755)
if err != nil {
log.Fatalf("creating directory for f-droid repo index file: %s\n", err.Error())
}
f, err := os.OpenFile(fdroidIndexFilePath, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
log.Fatalf("creating default f-droid repo index file: %s\n", err.Error())
}
defer f.Close()
err = json.NewEncoder(f).Encode(defaultIndex)
if err != nil {
log.Fatalf("writing default f-droid repo index: %s\n", err.Error())
}
}
initialFdroidIndex, err := apps.ReadIndex(fdroidIndexFilePath)
if err != nil {
log.Fatalf("reading f-droid repo index: %s\n", err.Error())
}
err = os.MkdirAll(*repoDir, 0o644)
if err != nil {
log.Fatalf("creating repo directory: %s\n", err.Error())
}
fmt.Println("::endgroup::Initializing")
var (
haveError bool
apkInfoMap = make(map[string]apps.Application)
toRemovePaths []string
changedRepos = make(map[string]map[string]*github.RepositoryRelease)
mu sync.Mutex
// wg sync.WaitGroup
)
hasNewCommits := false
for _, repo := range reposList {
// Log GitHub API rate limit
rate, _, err := githubClient.RateLimits(context.Background())
if err != nil {
log.Printf("Error getting rate limit: %v", err)
} else {
log.Printf("GitHub API Rate Limit: %d/%d, Reset: %s",
rate.Core.Remaining, rate.Core.Limit, rate.Core.Reset.Format(time.DateTime))
}
// wg.Add(1)
// go func(repo apps.Repo) {
// defer wg.Done()
fmt.Printf("::group::Repo: %s/%s\n", repo.Owner, repo.Name)
err, releases := getRepositoryReleases(githubClient, repo)
if err != nil {
log.Printf("Error while listing repo releases for %q: %s\n", repo.GitURL, err.Error())
mu.Lock()
haveError = true
mu.Unlock()
return
}
log.Printf("Received %d releases", len(releases))
var appWg sync.WaitGroup
repoChanged := false
for _, app := range repo.Applications {
appWg.Add(1)
go func(app apps.Application) {
defer appWg.Done()
fmt.Printf("::group::App %s\n", app.Name)
foundArtifact := false
for _, release := range releases {
fmt.Printf("::group::Release %s\n", release.GetTagName())
if release.GetDraft() {
log.Printf("Skipping draft %q\n", release.GetTagName())
continue
}
if release.GetTagName() == "" {
log.Printf("Skipping release with empty tag name")
continue
}
log.Printf("Working on release with tag name %q", release.GetTagName())
var apk *github.ReleaseAsset = apps.FindAPK(release, app.Filename)
if apk == nil {
log.Printf("Couldn't find any F-Droid assets for application %s in %s with file name %s", app.Filename, release.GetName(), app.Filename)
continue
}
appName := apps.GenerateReleaseFilename(app.Id, release.GetTagName())
log.Printf("Target APK name: %s\n", appName)
appClone := app
appClone.ReleaseDescription = release.GetBody()
if appClone.ReleaseDescription != "" {
log.Printf("Release notes: \n%s\n", appClone.ReleaseDescription)
}
mu.Lock()
apkInfoMap[appName] = appClone
mu.Unlock()
appTargetPath := filepath.Join(*repoDir, appName)
// If the app file already exists for this version, we stop processing this app and move to the next
if _, err := os.Stat(appTargetPath); !errors.Is(err, os.ErrNotExist) {
log.Printf("Already have APK for version %q at %q\n", release.GetTagName(), appTargetPath)
foundArtifact = true
break
}
log.Printf("Downloading APK %q from release %q to %q", apk.GetName(), release.GetTagName(), appTargetPath)
downloadContext, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
appStream, _, err := githubClient.Repositories.DownloadReleaseAsset(downloadContext, repo.Owner, repo.Name, apk.GetID(), http.DefaultClient)
if err != nil {
log.Printf("Error while downloading app %q (artifact id %d) from from release %q: %s", repo.GitURL, apk.GetID(), release.GetTagName(), err.Error())
mu.Lock()
haveError = true
mu.Unlock()
break
}
err = downloadStream(appTargetPath, appStream)
if err != nil {
log.Printf("Error while downloading app %q (artifact id %d) from from release %q to %q: %s", repo.GitURL, *apk.ID, *release.TagName, appTargetPath, err.Error())
mu.Lock()
haveError = true
mu.Unlock()
break
}
log.Printf("Successfully downloaded app for version %q", release.GetTagName())
fmt.Printf("::endgroup:App %s\n", app.Name)
mu.Lock()
hasNewCommits = true
repoChanged = true
if changedRepos[repo.GitURL] == nil {
changedRepos[repo.GitURL] = make(map[string]*github.RepositoryRelease)
}
changedRepos[repo.GitURL][app.Filename] = release
mu.Unlock()
break
}
if foundArtifact || haveError {
// Stop after the first [release] of this [app] is downloaded to prevent back-filling legacy releases.
return
}
}(app)
}
appWg.Wait()
if repoChanged {
log.Printf("Changes detected for repo: %s", repo.GitURL)
}
fmt.Printf("::endgroup::Repo: %s/%s\n", repo.Owner, repo.Name)
// }(repo)
}
// wg.Wait()
var commitMsg strings.Builder
if hasNewCommits {
log.Printf("New commits detected in at least one repo. Creating commit message with application update details.")
// Create the first line with repo names
repoNames := make([]string, 0, len(changedRepos))
for repoURL := range changedRepos {
repoName := strings.TrimPrefix(repoURL, "https://github.com/")
repoNames = append(repoNames, repoName)
}
commitMsg.WriteString(fmt.Sprintf("Updated apps from %s\n\n", strings.Join(repoNames, ", ")))
commitMsg.WriteString("## Repository updates:\n")
// Add details for each repo
for repoURL, apps := range changedRepos {
repoFullName := strings.TrimPrefix(repoURL, "https://github.com/")
commitMsg.WriteString(fmt.Sprintf("<details>\n<summary>%s</summary>\n\n", repoFullName))
// Group apps by release
releaseApps := make(map[*github.RepositoryRelease][]string)
for appFilename, release := range apps {
releaseApps[release] = append(releaseApps[release], appFilename)
}
for release, appList := range releaseApps {
releaseName := release.GetName()
if releaseName == "" {
releaseName = release.GetTagName()
}
releaseTagURL := release.GetHTMLURL()
commitMsg.WriteString(fmt.Sprintf("### [%s](%s)\n\n", releaseName, releaseTagURL))
for _, appFilename := range appList {
commitMsg.WriteString(fmt.Sprintf("- %s\n", appFilename))
}
commitMsg.WriteString("\n")
}
commitMsg.WriteString("</details>\n\n")
}
} else {
log.Printf("No new commits detected.")
}
if haveError {
os.Exit(1)
}
if !*debugMode {
fmt.Println("::group::F-Droid: Creating metadata stubs")
// Now, we run the fdroid update command
cmd := exec.Command("fdroid", "update", "--pretty", "--create-metadata", "--delete-unknown")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Dir = filepath.Dir(*repoDir)
log.Printf("Running %q in %s", cmd.String(), cmd.Dir)
err = cmd.Run()
if err != nil {
log.Println("Error while running \"fdroid update -c\":", err.Error())
fmt.Println("::endgroup::F-Droid: Creating metadata stubs")
os.Exit(1)
}
fmt.Println("::endgroup::F-Droid Creating metadata stubs")
}
fmt.Println("Filling in metadata")
fdroidIndex, err := apps.ReadIndex(fdroidIndexFilePath)
if err != nil {
log.Fatalf("reading f-droid repo index: %s\n::endgroup::\n", err.Error())
}
walkPath := filepath.Join(filepath.Dir(*repoDir), "metadata")
err = filepath.WalkDir(walkPath, func(path string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() || !strings.HasSuffix(path, ".yml") {
return err
}
pkgname := strings.TrimSuffix(filepath.Base(path), ".yml")
fmt.Printf("::group::Package %s\n", pkgname)
return func() error {
defer fmt.Printf("::endgroup::Package %s\n", pkgname)
log.Printf("Working on %q", pkgname)
meta, err := apps.ReadMetaFile(path)
if err != nil {
log.Printf("Reading meta file %q: %s", path, err.Error())
return nil
}
latestPackage, ok := fdroidIndex.FindLatestPackage(pkgname)
if !ok {
return nil
}
log.Printf("The latest version is %q with versionCode %d", latestPackage.VersionName, latestPackage.VersionCode)
apkInfo, ok := apkInfoMap[latestPackage.ApkName]
if !ok {
log.Printf("Cannot find apk info for %q", latestPackage.ApkName)
return nil
}
// Now update with some info
for _, repo := range reposList {
if repoApp, ok := apkInfoMap[latestPackage.ApkName]; ok && repoHasApp(repo, repoApp.Id) {
setNonEmpty(meta, "AuthorName", repo.AuthorName)
setNonEmpty(meta, "License", repo.License)
setNonEmpty(meta, "SourceCode", repo.GitURL)
summary := repo.Summary
// See https://f-droid.org/en/docs/Build_Metadata_Reference/#Summary for max length
const maxSummaryLength = 80
if len([]rune(summary)) > maxSummaryLength {
summary = string([]rune(summary)[:maxSummaryLength-3]) + "..."
log.Printf("Truncated summary to length of %d runes (max length)", len([]rune(summary)))
}
setNonEmpty(meta, "Summary", summary)
break // Found the repo, no need to continue
}
}
fn := apkInfo.Name
if fn == "" {
fn = apkInfo.Id
}
setNonEmpty(meta, "Name", fn)
setNonEmpty(meta, "Description", apkInfo.Description)
if len(apkInfo.Categories) != 0 {
meta["Categories"] = apkInfo.Categories
}
if len(apkInfo.AntiFeatures) != 0 {
meta["AntiFeatures"] = strings.Join(apkInfo.AntiFeatures, ",")
}
meta["CurrentVersion"] = latestPackage.VersionName
meta["CurrentVersionCode"] = latestPackage.VersionCode
log.Printf("Set current version info to versionName=%q, versionCode=%d", latestPackage.VersionName, latestPackage.VersionCode)
err = apps.WriteMetaFile(path, meta)
if err != nil {
log.Printf("Writing meta file %q: %s", path, err.Error())
return nil
}
log.Printf("Updated metadata file %q", path)
if apkInfo.ReleaseDescription != "" {
destFilePath := filepath.Join(walkPath, latestPackage.PackageName, "en-US", "changelogs", fmt.Sprintf("%d.txt", latestPackage.VersionCode))
err = os.MkdirAll(filepath.Dir(destFilePath), os.ModePerm)
if err != nil {
log.Printf("Creating directory for changelog file %q: %s", destFilePath, err.Error())
return nil
}
err = os.WriteFile(destFilePath, []byte(apkInfo.ReleaseDescription), os.ModePerm)
if err != nil {
log.Printf("Writing changelog file %q: %s", destFilePath, err.Error())
return nil
}
log.Printf("Wrote release notes to %q", destFilePath)
}
// Find the repo for this package
var repoForPackage *apps.Repo
for _, repo := range reposList {
if repoHasApp(repo, latestPackage.PackageName) {
repoForPackage = &repo
break
}
}
if repoForPackage == nil {
log.Printf("Could not find repo for package %s", latestPackage.PackageName)
return nil
}
log.Printf("Cloning git repository to search for screenshots")
gitRepoPath, err := git.CloneRepo(repoForPackage.GitURL)
if err != nil {
log.Printf("Cloning git repo from %q: %s", repoForPackage.GitURL, err.Error())
return nil
}
defer os.RemoveAll(gitRepoPath)
metadata, err := apps.FindMetadata(gitRepoPath)
if err != nil {
log.Printf("finding metadata in git repo %q: %s", gitRepoPath, err.Error())
return nil
}
log.Printf("Found %d screenshots", len(metadata.Screenshots))
screenshotsPath := filepath.Join(walkPath, latestPackage.PackageName, "en-US", "phoneScreenshots")
_ = os.RemoveAll(screenshotsPath)
var sccounter int = 1
for _, sc := range metadata.Screenshots {
var ext = filepath.Ext(sc)
if ext == "" {
log.Printf("Invalid: screenshot file extension is empty for %q", sc)
continue
}
var newFilePath = filepath.Join(screenshotsPath, fmt.Sprintf("%d%s", sccounter, ext))
err = os.MkdirAll(filepath.Dir(newFilePath), os.ModePerm)
if err != nil {
log.Printf("Creating directory for screenshot file %q: %s", newFilePath, err.Error())
return nil
}
err = file.Move(sc, newFilePath)
if err != nil {
log.Printf("Moving screenshot file %q to %q: %s", sc, newFilePath, err.Error())
return nil
}
log.Printf("Wrote screenshot to %s", newFilePath)
sccounter++
}
toRemovePaths = append(toRemovePaths, screenshotsPath)
return nil
}()
})
if err != nil {
log.Printf("Error while walking metadata: %s", err.Error())
os.Exit(1)
}
if !*debugMode {
fmt.Println("::group::F-Droid: Reading updated metadata")
// Now, we run the fdroid update command again to regenerate the index with our new metadata
cmd := exec.Command("fdroid", "update", "--pretty", "--delete-unknown")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Dir = filepath.Dir(*repoDir)
log.Printf("Running %q in %s", cmd.String(), cmd.Dir)
err = cmd.Run()
if err != nil {
log.Println("Error while running \"fdroid update -c\":", err.Error())
fmt.Println("::endgroup::F-Droid: Reading updated metadata")
os.Exit(1)
}
fmt.Println("::endgroup::F-Droid: Reading updated metadata")
}
fmt.Println("::group::Assessing changes")
// Now at the end, we read the index again
fdroidIndex, err = apps.ReadIndex(fdroidIndexFilePath)
if err != nil {
log.Fatalf("reading f-droid repo index: %s\n::endgroup::\n", err.Error())
}
// update lastUpdated and added correctly
for _, app := range fdroidIndex.Apps {
pkg, ok := fdroidIndex.Packages[app["packageName"].(string)]
if !ok || len(pkg) == 0 {
log.Printf("Invalid packageName: %v", app["packageName"])
continue
}
repoApp, ok := apkInfoMap[pkg[0].ApkName]
if ok && strings.TrimSpace(repoApp.LastUpdated) != "" {
t, err := time.Parse(time.RFC3339, repoApp.LastUpdated)
if err != nil {
log.Printf("Error parsing time: %v", err)
continue
}
app["lastUpdated"] = float64(t.UnixMilli())
app["added"] = float64(t.UnixMilli())
}
}
for _, pkgs := range fdroidIndex.Packages {
for i := range pkgs {
repoApp, ok := apkInfoMap[pkgs[i].ApkName]
if ok && strings.TrimSpace(repoApp.LastUpdated) != "" {
t, err := time.Parse(time.RFC3339, repoApp.LastUpdated)
if err != nil {
log.Printf("Error parsing time: %v", err)
continue
}
pkgs[i].Added = int64(t.UnixMilli()) // 通过索引修改原始值
}
}
}
apps.WriteIndex(fdroidIndexFilePath, fdroidIndex)
if !*debugMode {
fmt.Println("::group::F-Droid: Signing index")
// Now, we run the fdroid update command again to regenerate the index with our new metadata
cmd := exec.Command("fdroid", "signindex")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Dir = filepath.Dir(*repoDir)
log.Printf("Running %q in %s", cmd.String(), cmd.Dir)
err = cmd.Run()
if err != nil {
log.Printf("Error while signing index: %s", err.Error())
}
fmt.Println("::endgroup::F-Droid: Signing index")
}
// Now we can remove all paths that were marked for doing so
for _, rmpath := range toRemovePaths {
err = os.RemoveAll(rmpath)
if err != nil {
log.Fatalf("removing path %q: %s\n", rmpath, err.Error())
}
}
// We can now generate the README file
readmePath := filepath.Join(filepath.Dir(filepath.Dir(*repoDir)), "README.md")
// Extract fingerprint from the repoDir/index.html file
// <a href="https://*?fingerprint=*">
html, err := os.ReadFile(filepath.Join(*repoDir, "index.html"))
if err != nil {
log.Fatalf("reading index.html: %s\n::endgroup::\n", err.Error())
}
re := regexp.MustCompile(`a href="https://.*?\?fingerprint=.*?"`)
matches := re.FindSubmatch(html)
if len(matches) == 0 {
log.Fatalf("cannot find fingerprint url in index.html")
}
repoURL := string(matches[0][8 : len(matches[0])-1])
err = md.RegenerateReadme(readmePath, fdroidIndex, repoURL)
if err != nil {
log.Fatalf("error generating %q: %s\n", readmePath, err.Error())
}
cpath, haveSignificantChanges := apps.HasSignificantChanges(initialFdroidIndex, fdroidIndex)
if haveSignificantChanges {
log.Printf("The index %q had a significant change at JSON path %q", fdroidIndexFilePath, cpath)
// If there were no new commits, we add a commit title indicating index has changes.
if !hasNewCommits {
commitMsg.WriteString("Automatic index update\n\n")
}
commitMsg.WriteString("Index updated to reflect recent changes to the F-Droid repository.\n")
} else {
log.Printf("The index files didn't change significantly")
changedFiles, err := git.GetChangedFileNames(*repoDir)
if err != nil {
log.Fatalf("getting changed files: %s\n::endgroup::\n", err.Error())
}
// If only the index files changed, we ignore the commit
var modifiedFiles []string
for _, fname := range changedFiles {
if !strings.Contains(fname, "index") {
haveSignificantChanges = true
modifiedFiles = append(modifiedFiles, fname)
log.Printf("File %q is a significant change", fname)
}
}
// If there were modified files, we add them to the commit message
if len(modifiedFiles) > 0 {
// If there were no new commits, we add a commit title indicating only metadata changes occurred.
if !hasNewCommits {
commitMsg.WriteString("Automatic metadata updates\n\n")
}
commitMsg.WriteString("## Metadata updates:\n\n")
for _, fname := range modifiedFiles {
commitMsg.WriteString(fmt.Sprintf(" - %s\n", fname))
}
}
}
if haveError {
os.Exit(1)
}
fmt.Println("::endgroup::Assessing changes")
// If we don't have any good changes, we report it with exit code 2
if !haveSignificantChanges {
os.Exit(2)
}
// If we have relevant changes, we write the commit message and exit with code 0.
// Create a temporary commit message file.
tempFile, err := os.Create(*commitMsgFile)
if err != nil {
log.Fatalf("Error creating commit message file: %v", err)
}
defer tempFile.Close()
log.Printf("Commit message file created: %s", *commitMsgFile)
// Write the commit message to the file.
_, err = tempFile.WriteString(commitMsg.String())
if err != nil {
log.Printf("Error writing commit message file: %s", err)
} else {
log.Printf("Commit message written to %s\n%s", *commitMsgFile, commitMsg.String())
}
}
func getRepositoryReleases(githubClient *github.Client, repo apps.Repo) (error, []*github.RepositoryRelease) {
log.Printf("Looking up %s/%s on GitHub", repo.Owner, repo.Name)
gitHubRepo, _, err := githubClient.Repositories.Get(context.Background(), repo.Owner, repo.Name)
if err != nil {
log.Printf("Error while looking up repo: %s", err.Error())
} else {
repo.Summary = gitHubRepo.GetDescription()
if gitHubRepo.License != nil && gitHubRepo.License.SPDXID != nil {
repo.License = *gitHubRepo.License.SPDXID
}
log.Printf("Data from GitHub: summary=%q, license=%q", repo.Summary, repo.License)
}
releases, err := apps.ListAllReleases(githubClient, repo.Owner, repo.Name)
return err, releases
}
func setNonEmpty(m map[string]interface{}, key string, value string) {
if value != "" || m[key] == "Unknown" {
m[key] = value
log.Printf("Set %s to %q", key, value)
}
}
func downloadStream(targetFile string, rc io.ReadCloser) (err error) {
defer rc.Close()
targetTemp := targetFile + ".tmp"
f, err := os.Create(targetTemp)
if err != nil {
return
}
_, err = io.Copy(f, rc)
if err != nil {
_ = f.Close()
_ = os.Remove(targetTemp)
return
}
err = f.Close()
if err != nil {
return
}
return os.Rename(targetTemp, targetFile)
}
func repoHasApp(repo apps.Repo, packageName string) bool {
for _, app := range repo.Applications {
if app.Id == packageName {
return true
}
}
return false
}