8000 create_tag() and annotated tags · Issue #378 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content
create_tag() and annotated tags #378
Closed
@frossie

Description

@frossie

I am a bit confused as to how to create an annotated tag, in that what seems to be the documented way doesn't actually create an annotated tag. It may be a bug, or I may be an idiot. If the latter, I promise to send a PR with documentation patches :-)

The github3 documentation implies that this is sufficient:

backtag = repo.create_tag(tag = version,
                        message = message,
                          sha = commit,
                          obj_type = 'commit',
                          tagger = tagger,
                          lightweight = False)

However the resulting tag is not an annotated tag. In the outptut below, fe-888 is a tag created as above with github3:

; git show fe-888
commit d7f989bcd8f9fb3124096d8aa25e588f59bd4770
Author: Frossie <frossie@lsst.org>
Date:   Mon Apr 20 16:22:38 2015 -0700

    Update csv_test.csv

and fe-999 is a tag created with git tag -a and then pushed.

; git show fe-999
tag fe-999
Tagger: Frossie Economou <frossie@lsst.org>
Date:   Tue May 12 08:41:10 2015 -0700

This is how it works

commit d7f989bcd8f9fb3124096d8aa25e588f59bd4770
Author: Frossie <frossie@lsst.org>
Date:   Mon Apr 20 16:22:38 2015 -0700

    Update csv_test.csv

You can see the annotation of the message only in the latter.

The documentation implies that if create_tag succeeds, a Tag object is returned, which does indeed seem to be the case - eg this code snippet

backtag = repo.create_tag(tag = version,
                        message = message,
                          sha = commit,
                          obj_type = 'commit',
                          tagger = tagger,
                          lightweight = False)

print "TYPE", type(backtag)
print 'message', backtag.message
print 'tagger',  backtag.tagger
print 'object', backtag.object

results in:

TYPE <class 'github3.git.Tag'>
message Version fe-888 release
tagger {u'date': u'2015-12-11T09:01:45Z', u'name': u'frossie', u'email': u'frossie@lsst.org'}
object <Git Object [d7f989bcd8f9fb3124096d8aa25e588f59bd4770]>

Looking at the actual POST output from github3, I think I may (?) see the problem:

What I see is the POST to https://api.github.com/repos/frossie/test/git/tags with what seems to be all the correct information:

POST https://api.github.com/repos/frossie/test/git/tags with {"tagger": {"date": "2015-12-11T09:01:45Z", "email": "frossie@lsst.org", "name": "frossie"}, "message": "Version fe-888 release", "tag": "fe-888", "type": "commit", "object": "d7f989bcd8f9fb3124096d8aa25e588f59bd4770"}, {}

The returned tag object is:

BACKTAG
{
    "message": "Version fe-888 release",
    "object": {
        "sha": "d7f989bcd8f9fb3124096d8aa25e588f59bd4770",
        "type": "commit",
        "url": "https://api.github.com/repos/frossie/test/git/commits/d7f989bcd8f9fb3124096d8aa25e588f59bd4770"
    },
    "sha": "07f7b75b542e3584b545298eacb2b8b49d2457d8",
    "tag": "fe-888",
    "tagger": {
        "date": "2015-12-11T09:01:45Z",
        "email": "frossie@lsst.org",
        "name": "frossie"
    },
    "url": "https://api.github.com/repos/frossie/test/git/tags/07f7b75b542e3584b545298eacb2b8b49d2457d8"
}

All good. However when it goes on to create the reference required for an annotated tag, the POST reads:

POST https://api.github.com/repos/frossie/test/git/refs with {"sha": "d7f989bcd8f9fb3124096d8aa25e588f59bd4770", "ref": "refs/tags/fe-888"}, {}

Is this right? Because the Github API docs imply that the way to create an annotated tag is to create a tag objects and then a reference to it. That, I think, means that the second sha should be the sha of the returned tag.sha not the sha of the returned tag.object.sha - in other words I think it should be sending 07f7b instead of the commit sha, d7f98 ?

[See also https://stackoverflow.com/questions/15672547/how-to-tag-a-commit-in-api-using-curl-command]

The problem is that I cannot recover by creating the follow-up ref myself with create_ref because at that point create_tag has already created the ref and the API complains.

My full test script is at https://gist.github.com/frossie/b9f74562da26c3f278c9 but it's really not much more than the above.

I'm on 0.9.4 but couldn't see any obvious changes there at first glance, so I don't think that's the problem.

[Take pity if this is obvious, it's my first time with Python and the Github API]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0