Comments (3)
Hiya @tanrikut, support for push changes api is not added to the library, sorry about that. I will add it in next version release. Meanwhile you can use RestClient, it has few overload methods that creates the request URL and gets the reponse from Api. You can read about it more here.
Here is the sample code to get started. I've used the example from documentation.
var webApi = new AzDClientApi("org", "proj", "token");
var git = webApi.getGitApi();
var repo = git.getRepository("myRepository");
var refUpdate = new GitRefUpdate();
refUpdate.setName("refs/heads/myfirstbranch");
refUpdate.setOldObjectId("b92a68a4cd54506d0d8e264ddddbfe5076dca910");
// Create commits
var commits = new GitCommitRefs();
var commit = new GitCommitRef();
// Commit changes
var commitChange = new GitChange();
commitChange.setChangeType(VersionControlChangeType.EDIT);
commitChange.setItem("/tasks/content/activetasks.md");
commitChange.setNewContent(new ItemContent(){{
setContent("# My Active Tasks\\n\\n* Item 1\\n* Item 2\\n* Item 3\\n* Item 4\\n* Item 5\\n");
setContentType(ItemContentType.RAWTEXT);
}});
// Set commit properties
commit.setComment("Updating active tasks, but saving in a new branch.");
commit.setChanges(List.of(commitChange));
// Set the commits
commits.setGitCommitRefs(List.of(commit));
var requestBody = new HashMap<String, Object>(){{
put("refUpdates", refUpdate);
put("commits", commits);
}};
var response = RestClient.send(RequestMethod.POST, webApi.getConnection(), ResourceId.GIT,
webApi.getConnection().getProject(), "git/repositories", repo.getId(), null, "7.0",
null, requestBody, CustomHeader.JSON_CONTENT_TYPE);
// Unmarshal the json
var mapper = new JsonMapper();
mapper.mapJsonResponse(response, GitPush.class); // GitPush class doesn't exists in the library. You have to use the scrape.py to get the definition files and add it your project.
GitPush
type definition doesn't exists in the library, you can use scrape.py under tools and extract the type definitions. Then you can deserialise the json response to POJO.
Let me know how it goes.
Cheers.
from azure-devops-java-sdk.
@tanrikut, version 5.0.6 is released and has support to git push. You can do something like below.
var webApi = new AzDClientApi("org", "proj", "token"); // Here token is your personal access token.
var git = webApi.getGitApi();
var repository = git.getRepository("myRepository");
var gitPush = new GitPush();
var refUpdate = new GitRefUpdate();
refUpdate.setName("refs/heads/myfirstbranch");
refUpdate.setOldObjectId("b92a68a4cd54506d0d8e264ddddbfe5076dca910");
// Create commits
var commit = new GitCommitRef();
// Commit changes
var commitChange = new GitChange();
commitChange.setChangeType(VersionControlChangeType.EDIT);
commitChange.setItem("/tasks/content/activetasks.md");
commitChange.setNewContent(new ItemContent(){{
setContent("# My Active Tasks\\n\\n* Item 1\\n* Item 2\\n* Item 3\\n* Item 4\\n* Item 5\\n");
setContentType(ItemContentType.RAWTEXT);
}});
// Set commit properties
commit.setComment("Updating active tasks, but saving in a new branch.");
commit.setChanges(List.of(commitChange));
gitPush.setRefUpdates(List.of(refUpdate));
gitPush.setCommits(List.of(commit));
git.createPush(repository.getId(), gitPush);
I'm closing the issue for now.
from azure-devops-java-sdk.
Thanks, well done
from azure-devops-java-sdk.
Related Issues (20)
- Documentation of RestClient or Unit tests of RestClient needed HOT 3
- Possible to compile with Java 8 HOT 5
- GitRepository does not support repositories with size greater than 2147483647 bytes HOT 2
- Add ability to get Retry-After value in response header HOT 2
- Parsing exception for ReleaseDefinition that has an an Environment that has Conditions. HOT 1
- Enhance the API to connect to on premise Azure DevOps server HOT 6
- GitApi 'getItems' does not include version in query string
- Git push does not work because JSON output does not match examples HOT 3
- Do you support pagination with the continuationToken HOT 11
- [Feature] Missing Pull Request Statuses object HOT 2
- [Improvement] Add more examples to GitApi.md HOT 1
- How to get the get the team capacity? HOT 2
- Azure Server HOT 6
- [Improvement] Add ability for GitApi.getRepositories() to include hidden repositories HOT 4
- Announcement!!!
- [CORE API] getTeams() Fails with ApiResponseParsingException: No content to map due to end-of-input at [Source: (String)""; line: 1, column: 0] HOT 4
- GitPullRequest getCommits() is always null HOT 3
- CVE "sonatype-2022-6438" HOT 3
- VariableGroupMap always assign the same value to variables HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-devops-java-sdk.