Go-github: IssuesService.Edit cannot clear an issue's milestone

Created on 22 Sep 2015  路  6Comments  路  Source: google/go-github

Much like #181 I fail to see how to use go-github to clear an issue's milestone. The API requires the milestone be to set to null in the request so that it is cleared, but that is not possible since the field uses omitempty.

Not sure what the right solution would be, perhaps a standalone method for clearing milestones?

bug

Most helpful comment

Indeed, we can workaround it like that (tested) :

       u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, issue)
       req, err := githubCli.NewRequest("PATCH", u, &struct {
               Milestone interface{} `json:"milestone"`
       }{})
       if err != nil {
               return err
       }
       _, err = githubCli.Do(req, nil)
       if err != nil {
               return err
       }

All 6 comments

Is there a workaround for this ?
If no I think a dedicated method is the way to go, something like RemoveMilestonelForIssue, I can work on this.

The workaround is to send the request manually. You can basically copy EditMilestone and put your own struct there.

Indeed, we can workaround it like that (tested) :

       u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, issue)
       req, err := githubCli.NewRequest("PATCH", u, &struct {
               Milestone interface{} `json:"milestone"`
       }{})
       if err != nil {
               return err
       }
       _, err = githubCli.Do(req, nil)
       if err != nil {
               return err
       }

I'm surprised this hasn't been addressed in 2 years, though it's clear it's a problem as @marun has mentioned above. Should we add a removeMilestone method to the IssuesService?

Dropping omitempty is not really an option as there is no distinction between an absent field and a null field in a struct. Another option would be adding a boolean removeMilestone parameter to IssuesService.Edit, but would be a breaking change and make the API awkward to use.

I think that's the case because the GitHub API is very large, and removing a milestone from an issue is something only a few people ever need. It has a well described workaround here, so those who need it use that and move on.

To resolve the issue, we need to come up with a good API/good way of doing so.

Nice to see @elliott-beach again - this issue manifests as a bug with much head scratching and wasted time. Perhaps now that there are multiple consumers with this specific issue, we could fix this issue using this library. What are your thoughts 3 years on?

Alex

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smola picture smola  路  3Comments

zulhfreelancer picture zulhfreelancer  路  3Comments

gmlewis picture gmlewis  路  3Comments

OGKevin picture OGKevin  路  3Comments

gmlewis picture gmlewis  路  3Comments