Repository: PyGithub/PyGithub

Issue:
cannot create a correct release from tag when using create_git_tag_and_release
There is an issue when using create_git_tag_and_release function to create a release in Repository.py.

`   def create_git_tag_and_release(
        self,
        tag,
        tag_message,
        release_name,
        release_message,
        object,
        type,
        tagger=github.GithubObject.NotSet,
        draft=False,
        prerelease=False,
    ):
        self.create_git_tag(tag, tag_message, object, type, tagger)
        return self.create_git_release(
            tag, release_name, release_message, draft, prerelease
        )`

The code cannot create a correct commit id from the created tag. please help to fix it. thanks.


Discussion:
So let's break it down further. Since Repository.create_git_tag_and_release() fails to create a tag pointing to the correct commit, does Repository.create_git_tag() also show the same behaviour? Do you have an example you can show us?
Repository.create_git_tag()  works fine, instead I use the Repository.create_git_release() which can can create both a correct release and tag for me with a correct commit id. 

From the source code, I found there is no passing a parameter pointing to the commit info:
        return self.create_git_release(tag, release_name, release_message, draft, prerelease)
it should provide target_commitish parameter.

Not sure my idea is correct.

It's a good theory, worth checking out. Thanks for your explanation, that helps me work out what is going on. I'll investigate this based on your information.
+1, noticed following:
`create_git_tag_and_release(tag="v1.2", object="commit_sha", ...)`
Expected behaviour:
  1) created tag with name "v1.2"
  2) this tag points to commit "commit_sha"
  3) created release associated with tag "v1.2"

Real behaviour
  1) tag is probably created via `create_git_tag`, but
  2) tag IS NOT referencing commit "commit_sha"
  3) `create_git_release` creates another tag pointing to another (wrong) commit

Did following to fix behaviour:
  1) manually creating tag via `tag = create_git_tag(object=commit_sha, ...)`
  2) manually creating reference to the tag via `create_git_ref("refs/tags/v1.2", tag.sha)`
  3) making release via `create_git_release(tag.tag, ...)`

You could check, that create_git_tag doesn't creates reference via:
  - `create_git_tag(...)`
  - `git pull`
  - `git tag -v "tag_name"`
And without reference `create_git_release` doesn't take the tag into account when creating release.
Passing `target_commitish` probably will fix the issue
At least based on the code, the tag should reference the correct sha, since the object parameter is passed into create_git_tag() ...
yep, created tag is pointing to the correct revision, but the problem is that for some reason `create_git_tag` doesn't create reference (`refs/tags/...`) to the tag object sha and `create_git_release` ignores passed tag and creates new with the same name and according to the API that tag is pointing to the head of the default repository branch (for the case when `target_commitish` is not passed) (in our case it is the latest commit in the `develop` branch)
From https://developer.github.com/v3/git/tags/:

Note that creating a tag object does not create the reference that makes a tag in Git. If you want to create an annotated tag in Git, you have to do this call to create the tag object, and then create the refs/tags/[tag] reference.


Please don't conflate this bug with a different (and documented upstream!) issue.
OK, haven't read docs till the end.
Was a little bit confused with the sentence "The Git tags API only supports annotated tag objects, not lightweight tags."
But in fact in order to fix subject behaviour you need do one of the following (though i'm not sure, it's subject to test):
1) don't call `create_git_tag` and call `create_git_release` with `tag="tag_name", target_commitish="commit sha"`
2) call `create_git_tag`, create reference, call `create_git_release` as expected
3) call `create_git_tag`, call `create_git_release` with `tag=tag.name` and `target_commitish=tag.sha`

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -954,7 +954,12 @@ def create_git_tag_and_release(
     ):
         self.create_git_tag(tag, tag_message, object, type, tagger)
         return self.create_git_release(
-            tag, release_name, release_message, draft, prerelease
+            tag,
+            release_name,
+            release_message,
+            draft,
+            prerelease,
+            target_commitish=object,
         )
 
     def create_git_release(


Test patch:
diff --git a/tests/ReplayData/Release.testCreateGitTagAndRelease.txt b/tests/ReplayData/Release.testCreateGitTagAndRelease.txt
--- a/tests/ReplayData/Release.testCreateGitTagAndRelease.txt
+++ b/tests/ReplayData/Release.testCreateGitTagAndRelease.txt
@@ -37,7 +37,7 @@ api.github.com
 None
 /repos/edhollandAL/PyGithub/releases
 {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
-{"body": "release message", "prerelease": false, "tag_name": "v3.0.0", "draft": false, "name": "release title"}
+{"body": "release message", "prerelease": false, "tag_name": "v3.0.0", "draft": false, "name": "release title", "target_commitish": "5a05a5e58f682d315acd2447c87ac5b4d4fc55e8"}
 201
 [('content-length', '1648'), ('vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding'), ('x-served-by', 'd594a23ec74671eba905bf91ef329026'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('etag', '"7e6e27a070b656e2058a8c62f0648a57"'), ('location', 'https://api.github.com/repos/edhollandAL/PyGithub/releases/1210902'), ('access-control-allow-credentials', 'true'), ('status', '201 Created'), ('x-ratelimit-remaining', '4934'), ('x-github-media-type', 'github.v3; format=json'), ('access-control-expose-headers', 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', '56BCFFD3:54C9:7C07BE1:553A0689'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('date', 'Fri, 24 Apr 2015 09:02:02 GMT'), ('access-control-allow-origin', '*'), ('content-security-policy', "default-src 'none'"), ('strict-transport-security', 'max-age=31536000; includeSubdomains; preload'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('x-frame-options', 'deny'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1429867683')]
 {"url":"https://api.github.com/repos/edhollandAL/PyGithub/releases/1210902","assets_url":"https://api.github.com/repos/edhollandAL/PyGithub/releases/1210902/assets","upload_url":"https://uploads.github.com/repos/edhollandAL/PyGithub/releases/1210902/assets{?name}","html_url":"https://github.com/edhollandAL/PyGithub/releases/tag/v3.0.0","id":1210902,"tag_name":"v3.0.0","target_commitish":"master","name":"release title","draft":false,"author":{"login":"edhollandAL","id":11922660,"avatar_url":"https://avatars.githubusercontent.com/u/11922660?v=3","gravatar_id":"","url":"https://api.github.com/users/edhollandAL","html_url":"https://github.com/edhollandAL","followers_url":"https://api.github.com/users/edhollandAL/followers","following_url":"https://api.github.com/users/edhollandAL/following{/other_user}","gists_url":"https://api.github.com/users/edhollandAL/gists{/gist_id}","starred_url":"https://api.github.com/users/edhollandAL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edhollandAL/subscriptions","organizations_url":"https://api.github.com/users/edhollandAL/orgs","repos_url":"https://api.github.com/users/edhollandAL/repos","events_url":"https://api.github.com/users/edhollandAL/events{/privacy}","received_events_url":"https://api.github.com/users/edhollandAL/received_events","type":"User","site_admin":false},"prerelease":false,"created_at":"2015-04-15T20:53:41Z","published_at":"2015-04-24T09:02:02Z","assets":[],"tarball_url":"https://api.github.com/repos/edhollandAL/PyGithub/tarball/v3.0.0","zipball_url":"https://api.github.com/repos/edhollandAL/PyGithub/zipball/v3.0.0","body":"release message"}