We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// Deprecated func commit(ctx context.Context, client *github.Client, owner, repo, branch, message string, files []string) (string, error) { currentRef, _, err := client.Git.GetRef(ctx, owner, repo, "heads/"+branch) if err != nil { return "", fmt.Errorf("get ref: %w", err) } currentTree, _, err := client.Git.GetTree(ctx, owner, repo, currentRef.GetObject().GetSHA(), false) if err != nil { return "", fmt.Errorf("get tree: %w", err) } var entrys []github.TreeEntry for i := range files { info, err := os.Stat(files[i]) if err != nil { return "", fmt.Errorf("stat file: %w", err) } mode := fmt.Sprintf("100%o", info.Mode()) content, err := os.ReadFile(files[i]) if err != nil { return "", fmt.Errorf("open file: %w", err) } sha := sha1.New() sha.Write([]byte(fmt.Sprintf("blob %d", len(content)))) sha.Write([]byte{0}) sha.Write(content) localSHA := hex.EncodeToString(sha.Sum(nil)) changed := true for _, entrie := range currentTree.Entries { if entrie.GetPath() != files[i] { continue } if entrie.GetSHA() == localSHA && entrie.GetMode() == mode { changed = false } } log.Println(files[i], changed) if !changed { continue } blob, resp, err := client.Git.GetBlob(ctx, owner, repo, localSHA) if err != nil { if resp.StatusCode != http.StatusNotFound { return "", fmt.Errorf("get blob: %w", err) } log.Println("create blob") blob, _, err = client.Git.CreateBlob(ctx, owner, repo, &github.Blob{Content: github.String(string(content))}) if err != nil { return "", fmt.Errorf("create blob: %w", err) } } entrys = append(entrys, github.TreeEntry{ Path: github.String(files[i]), Mode: github.String(mode), Type: github.String("blob"), SHA: github.String(blob.GetSHA()), }) } log.Println(entrys) if len(entrys) == 0 { return "", nil } tree, _, err := client.Git.CreateTree(ctx, owner, repo, currentRef.GetObject().GetSHA(), entrys) if err != nil { return "", fmt.Errorf("create tree: %w", err) } log.Println(tree) parent, _, err := client.Git.GetCommit(ctx, owner, repo, currentRef.GetObject().GetSHA()) if err != nil { return "", fmt.Errorf("get parent commit: %w", err) } _, _, err = client.Git.CreateCommit(ctx, owner, repo, &github.Commit{ Message: github.String(message), Tree: tree, Parents: []github.Commit{*parent}, }, ) if err != nil { return "", fmt.Errorf("create commit: %w", err) } ref := &github.Reference{ Ref: github.String(currentRef.GetRef()), Object: &github.GitObject{SHA: github.String(currentRef.GetObject().GetSHA())}, } update, _, err := client.Git.UpdateRef(ctx, owner, repo, ref, false) if err != nil { return "", fmt.Errorf("update ref: %w", err) } return update.GetObject().GetSHA(), nil }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: