|
| 1 | +package org.kohsuke.github; |
| 2 | + |
| 3 | +import org.junit.After; |
| 4 | +import org.junit.Before; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | + |
| 9 | +import static org.junit.Assert.assertEquals; |
| 10 | +import static org.junit.Assert.assertNotNull; |
| 11 | + |
| 12 | +/** |
| 13 | + * |
| 14 | + * @author Martin van Zijl |
| 15 | + */ |
| 16 | +public class GHTagTest extends AbstractGitHubWireMockTest { |
| 17 | + |
| 18 | + @Before |
| 19 | + @After |
| 20 | + public void cleanUpTags() throws Exception { |
| 21 | + // Cleanup is only needed when proxying |
| 22 | + if (!mockGitHub.isUseProxy()) { |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + try { |
| 27 | + GHRef ref = getRepository(this.gitHubBeforeAfter).getRef("tags/create_tag_test"); |
| 28 | + if (ref != null) { |
| 29 | + ref.delete(); |
| 30 | + } |
| 31 | + } catch (IOException e) { |
| 32 | + // The reference probably does not exist. |
| 33 | + // This is safe to ignore. |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testCreateTag() throws Exception { |
| 39 | + GHRepository repo = getRepository(); |
| 40 | + |
| 41 | + String commitSha = "dfe47235cfdcaa12292dab3b1a84ca53a1ceadaf"; |
| 42 | + String tagName = "create_tag_test"; |
| 43 | + String tagMessage = "Test Tag"; |
| 44 | + String tagType = "commit"; |
| 45 | + |
| 46 | + GHTagObject tag = repo.createTag(tagName, tagMessage, commitSha, tagType); |
| 47 | + assertEquals(tagName, tag.getTag()); |
| 48 | + assertEquals(tagMessage, tag.getMessage()); |
| 49 | + assertEquals(commitSha, tag.getObject().getSha()); |
| 50 | + |
| 51 | + // Make a reference to the newly created tag. |
| 52 | + GHRef ref = repo.createRef("refs/tags/" + tagName, tag.getSha()); |
| 53 | + assertNotNull(ref); |
| 54 | + } |
| 55 | + |
| 56 | + protected GHRepository getRepository() throws IOException { |
| 57 | + return getRepository(gitHub); |
| 58 | + } |
| 59 | + |
| 60 | + private GHRepository getRepository(GitHub gitHub) throws IOException { |
| 61 | + return gitHub.getOrganization("github-api-test-org").getRepository("github-api"); |
| 62 | + } |
| 63 | +} |
0 commit comments