google / go-github

Go library for accessing the GitHub v3 API
https://pkg.go.dev/github.com/google/go-github/v66/github
BSD 3-Clause "New" or "Revised" License
10.43k stars 2.06k forks source link

Transactional support when updating multiple files #3029

Open Alansyf opened 10 months ago

Alansyf commented 10 months ago

Hi I understand the github api typically operates on individual requests. But in most my case here in my application, I must make sure two files (even more) are updated in a transactional way, like in database. Either both success or both failed.

I can implement something like revertFirstCommit to handle one by one, but this is too much efforts. Wondering if can from lib natively provide similar as we have in database commit/rollback.

err := dao.WithTransaction(dao.GetDB(), func(tx dao.Transaction) error {
        //
        for _, c := range tableColumnsList {
            err := dao.UpdateTableColumn(ctx, tx, c)
            if err != nil {
                zap.L().Sugar().Error(err)
                return err
            }
        }
        err := dao.UpdateTable(ctx, tx, tableDto)
        if err != nil {
            zap.L().Sugar().Error(err)
            return err
        }
gmlewis commented 10 months ago

This is the perfect opportunity for you to create a helper repo that is completely independent of this one, and once you get it working well, you can create a PR that points to it from our README.md just like we have done for the ghinstallation repo.

We decided long back that this repo will be dedicated to the core functionality of making the GitHub v3 API easy to use from the Go programming language, and that all other helpers should go in external repos. This is done for a number of reasons, and if you are inclined, you can search for the discussions we had years ago on this topic.

We'll leave this issue open for a while in case there is more discussion or in case you would like to use this issue to refer to from your PR where you update this repo's README.md.