-
Notifications
You must be signed in to change notification settings - Fork 272
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 git repository file #225
Conversation
@xuzhang3 anything else needed here to get this PR merged and released? 👍 |
|
@xuzhang3 that's awesome! Thank you and have a great weekend 😁👍 |
@phillebaba Can we add acceptances and document for this new resource? |
Sorry I had to prioritize other things before christmas. I have started working on the tests now as other things rely on this change. Do you think I need to mock the API to get things working @xuzhang3? |
Hi @phillebaba , If you cannot create the resource or the test resource depends on the third part service then you can mock the API, otherwise you should create real test resources. resource "azuredevops_project" "project" {
name = "Sample Project"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "repo" {
project_id = azuredevops_project.project.id
name = "Sample Empty Git Repository"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_git_repository_file" "repo_file" {
repository_id = azuredevops_git_repository.repo.id
file = "./test.go"
content = "#Managed by Terraform"
branch = ""
commit_message = "init commit"
overwrite_on_create = false
}
|
@xuzhang3 thanks for the help! I added some tests that will verify the simple CRUD flow, could you have a look? |
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.
Hi @phillebaba you need add xxx.markdown
file for azuredevops_git_repository_file
azuredevops/internal/acceptancetests/resource_git_repository_file_test.go
Outdated
Show resolved
Hide resolved
azuredevops/internal/acceptancetests/resource_git_repository_file_test.go
Show resolved
Hide resolved
azuredevops/internal/acceptancetests/resource_git_repository_file_test.go
Outdated
Show resolved
Hide resolved
azuredevops/internal/acceptancetests/resource_git_repository_file_test.go
Outdated
Show resolved
Hide resolved
}, | ||
"commit_message": { | ||
Type: schema.TypeString, | ||
Optional: true, |
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 would suggest change commit_message
to comment
. Since this is a git push comment, can we remove the Computed: true,
and change Optional
to Required
?
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 am trying to follow the standards set forward by the GitHub Terraform provider which has a similar resource. I would prefer if we could try to make this resource as similar as possible.
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.
@xuzhang3 and @phillebaba just wondering if you have any final decisions on whether commit_message
will change to comment
. The reason I ask is, we are forging ahead with a version of the provider in our environment. All other change decisions in this PR will not have a major effect on us in the future but the commit_message
change could mean we may have to do a lot of Terraform state manipulation down the track if we choose to go with commit_message
and the upstream chooses comment
.
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.
@russellmccloy-coles My suggestion is based on the git push api, service use comment
as commit-message
. I'm ok with commit_message
.
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.
In git command, it is called message git commit --message
. In API, it is comment
. If a simple word can represent the configuration meanings, I prefer the simple one.
azuredevops/internal/service/git/resource_git_repository_file.go
Outdated
Show resolved
Hide resolved
azuredevops/internal/service/git/resource_git_repository_file.go
Outdated
Show resolved
Hide resolved
azuredevops/internal/service/git/resource_git_repository_file.go
Outdated
Show resolved
Hide resolved
azuredevops/internal/service/git/resource_git_repository_file.go
Outdated
Show resolved
Hide resolved
if item != nil { | ||
if !overwriteOnCreate { | ||
return fmt.Errorf("Refusing to overwrite existing file. Configure `overwrite_on_create` to `true` to override.") | ||
} else { | ||
changeType = git.VersionControlChangeTypeValues.Edit | ||
} | ||
} |
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.
if item != nil { | |
if !overwriteOnCreate { | |
return fmt.Errorf("Refusing to overwrite existing file. Configure `overwrite_on_create` to `true` to override.") | |
} else { | |
changeType = git.VersionControlChangeTypeValues.Edit | |
} | |
} | |
if item != nil && !overwriteOnCreate { | |
return fmt.Errorf("Refusing to overwrite existing file. Configure `overwrite_on_create` to `true` to override.") | |
} | |
changeType = git.VersionControlChangeTypeValues.Edit |
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.
@xuzhang3 the logic you have suggested here is different to the original logic:
- if fails the test TestAccGitRepoFile_CreateAndUpdate
- changeType = git.VersionControlChangeTypeValues.Edit always gets run when line 161 is not run
Test result:
API server listening at: 127.0.0.1:42024
=== RUN TestAccGitRepoFile_CreateAndUpdate
testing.go:673: Step 0 error: errors during apply:
Error: The path 'foo.txt' does not exist at commit '64fba23b7b92e632619b0758c1eeb059fa685425'
Parameter name: newPush
on /tmp/tf-test256550528/main.tf line 2:
(source code not available)
--- FAIL: TestAccGitRepoFile_CreateAndUpdate (15.91s)
FAIL
Whereas in the original code if: item != nil
is true no further code gets run
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.
Yes you are right about this one. Idiomatic go seems to be about never using else statements so I will change this as the else statement is not required after the error is returned.
Hi @phillebaba , I'm keen to use this feature. Can I help with the PR? I'm happy to make the adjustments as per @xuzhang3 's request, and push it to another branch. Also happy to push to your branch, but I won't have permissions. cheers |
cf65937
to
d8d647e
Compare
@russellmccloy-coles sorry this keeps falling to the bottom of my backlog and I end up picking it up when I have the time. Do you want contributor permissions to my fork in case I become slow at responding again? Just make sure that you have signed the CLA in that case. @xuzhang3 the majority of the changes requested should be done now. I just need to run through the acceptance tests once more. I will try to be quick to respond from now on so that we can get this PR merged ASAP 😄 |
@phillebaba yes please... that would be great as we have this as our number one focus right now |
@phillebaba I know you are busy but any luck adding me as a contributor? |
azuredevops/internal/service/git/resource_git_repository_file.go
Outdated
Show resolved
Hide resolved
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.
@phillebaba Two changes:
getCommits
usebranch
inxxx
format while the parameter ingetLastCommitId
is inrefs/heads/xxx
format- If this resource support import, terraform should be able find the resource though APIs
@phillebaba just incase it helps. I have dumped my changes which we now have running in our environment into this branch on your repository: Notes:
|
|
Signed-off-by: Philip Laine <[email protected]>
f37ff39
to
42441b1
Compare
7ad90a2
to
b1026be
Compare
* update document * update error message * bug fix
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.
LGTM
This has honestly been very hard to test as the git API for Azure DevOps is not really documented plus there are a couple of bugs which have turned up from some of my testing. Using a git lib like libgit2 is not really possible so the API is the only option. This is only an initial feature implementation, and if you find issues fixing those would be very helpful for everyone! |
@xuzhang3 maybe this resource needs an "expiermental" status or something equivalent to that then |
Why not just fix the underlying bug instead? |
@drdamour this resource only cover a minimal features like create/push etc. of the AzGit repository files. Can out be more specific what bug it is or features you want? You can create a new issue for feature requirement. |
@xuzhang3 well that's what i'm asking, what's the feature it's supposed to support? becaues it's not just create, everytime i run an apply it applys a commit, that seems wrong |
@drdamour this is a bug, this resource get the last commit message from repo and treat it as local update. |
i went to open a bug, but saw you opened #557 thx |
This change adds a new resource type called
azuredevops_git_repository_file
which allows users to add files to the repositories they have created. Behavior wise it mimic the file resource in the GitHub provider, so that people who have used it should feel like this is familiar.The resource does not actually care about commit history but instead aims to make sure that the specified content in the specified file is present. If it is not it will update the content with a new commit.
Fixes #23