-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add github_branch data and resource #364
Add github_branch data and resource #364
Conversation
Partially addresses #286 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cornfeedhobo,
This looks great! 👍 I gave some minor feedback...
Something that may need more discussion is the name of the resource. I think github_repository_branch
is quite lengthy and github_branch
would suffice (I think it's obvious github_branch
would refer to a repo's branch).
Maybe @jcudit can weigh in here?
Stephen
@shoekstra Thanks for the review. I left some questions for you to clarify, but in general I'm happy to change anything you want. All your points are minor, including the resource name. github_branch is fine with me. Let me know what you think or if you want to wait for @jcudit before I make any follow up changes. Regards |
…use required fixtures
Bump. I addressed all the concerns I think. 🙏 |
👋 @cornfeedhobo - this is looking good so far. I think all that is missing is to update the
Docs for both the datasource and resource would be helpful. Also, I am in favour of |
Sincere apologies for the delayed response! I haven't had time to look at the test errors, I'll see if I can do that later today...
I worry this leads to bloated resource names and we should only include But I don't want to let a naming discussion block this functionality, so I'll create a separate issue to discuss. 🙂 |
I'm going to keep going with |
I'm going to verify importing before signing off on this. stand by. |
You can add a test for the importer functionality in your resource's integration tests, here's an example. |
@shoekstra interesting. It looks like my code already does that, but then doing some functional tests and I see that after import, the subsequent apply is attempting to update most of the attributes. Is it possible the test suites should have a follow up |
This is generally solved by adding those attributes to the resource's Read func so when the resource is refreshed those values are read and then stored in the state. You'll notice in Hope that helps! |
Fixes #401 |
@jcudit @shoekstra thanks for hanging in there! I believe this is ready now. |
@shoekstra Thanks for the review. I think I've addressed everything you've brought up. It also gave me the chance to clean up some other minor things. Have another look please, and I'll try to be fast about any final changes. Thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delayed feedback @cornfeedhobo!
Some minor changes, fairly certain after this it'll be good to merge 👍
Ping @jcudit to also give it a look see.
@shoekstra updated. thanks again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
👋 I've got this one on my radar and am happy with the outcome so far. Great work 😄 I'm focusing on merging a client change that would cause a minor conflict here when merged. Afterwards, I'll give this branch a thorough review pass and will either get it merged with the upcoming release or the one that follows. Thanks again for the contribution and patience. |
Thanks! We have some work that is probably 2 weeks out, and it would be great to have this in by then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a bunch of suggestions that will get the acceptance tests to run. Please commit the fixes if they look good.
This test consistently fails:
=== CONT TestAccGithubBranch_withSourceBranch
--- FAIL: TestAccGithubBranch_withSourceBranch (6.59s)
testing.go:654: Step 2 error: Error querying GitHub branch reference terraformtesting/test-repo (refs/heads/test-branch-jcduy:test-branch): no match found for this ref
FAIL
FAIL github.com/terraform-providers/terraform-provider-github/github 6.965s
Still investigating but appreciate help if anything comes to mind.
{ | ||
Config: testAccCheckGithubBranchDataSourceConfig(name, repo, "master"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(rn, "repository", repo), | ||
resource.TestCheckResourceAttr(rn, "branch", "master"), | ||
resource.TestCheckResourceAttrSet(rn, "etag"), | ||
resource.TestCheckResourceAttrSet(rn, "ref"), | ||
resource.TestCheckResourceAttrSet(rn, "sha"), | ||
), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a duplicate of the block above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcudit Yes. My understanding is that this checks for drift, essentially making sure my state doesn't accidentally drift between runs. This helped me catch an error with where I was setting etag
.
Config: testAccCheckGithubBranchDataSourceConfig(name, repo, "test-branch"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(rn, "repository", repo), | ||
resource.TestCheckResourceAttr(rn, "branch", "test-branch"), | ||
resource.TestCheckResourceAttrSet(rn, "etag"), | ||
resource.TestCheckResourceAttrSet(rn, "ref"), | ||
resource.TestCheckResourceAttrSet(rn, "sha"), | ||
), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a duplicate of the block above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same answer as above.
ImportStateId: fmt.Sprintf("%s:%s", repo, branch), | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"source_sha", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does work around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_sha
is extremely difficult to determine at import time. I dug through github's api and git. The best I figured out was an in-memory shallow clone and then parse the git state, but decided that was too much. It's just non-trivial to find the parent commit, and even once you do, it's not guaranteed accurate. It my testing I was getting
testing.go:654: Step 2 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) {
}
(map[string]string) (len=1) {
(string) (len=10) "source_sha": (string) (len=40) "18edb0e04930c3e4cff23fb837d3116898e0c6a6"
}
I assume this is because the way the tests are orchestrated because this new resource does not set it outside of Create
.
@jcudit The acceptance tests already ran here and locally - everything was fine. Did something change in master necessitating these? What's up - I'm lost. |
Sorry for the confusion @cornfeedhobo, there were changes merged around client and pointer use. These are the minor conflicts mentioned above. Not sure about the failing test as yet. |
Gotchya. On it! |
@jcudit I've addressed most everything and left a comment on the import state question. Unfortunately it looks like your travis config is broken right now. Ping me with your review and I'll kick off travis with an empty commit if all is good. Thanks! |
@cornfeedhobo - got it sorted, apologies for that interrupt. Can you try a rebase so we can validate tests are passing? |
@jcudit Look at that happy travis! thanks! P.S. Can you Squash Merge this when the time comes? |
Happy to see this one ship! Great feature, great collaboration and a lot of patience to get to this point. Thanks again for your efforts. |
Likewise. Thanks for the thoughtful reviews! |
* add github_repository_branch data and resource * rename github_repository_branch to github_branch and adjust tests to use required fixtures * nit * Trigger travis * Trigger travis * add github_branch documentation * revert go.sum change. * remove sha attribute * fix importing * include doc links * fix broken doc link * clean up github_branch: - add etag and sha attributes back - make errors more verbose for easier debugging - expand test case - require branch for data source * review * review * review * fix client references for github v3 client * fix util call * nit * fix import id when specifying source_branch
This PR adds a new resource for creating and managing Github repository branches. I find this useful for modules that codify Gitflow.
Please let me know if I can fix anything.