-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FTR-92: Add features to support wiki creation
- Loading branch information
Showing
10 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package azuredevops | ||
|
||
import ( | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/feed" | ||
) | ||
|
||
// GetPackageVersion gets all GitRepository | ||
func (a *AzureDevOps) GetPackageVersion(projectName string, feedName string) (*[]feed.Package, error) { | ||
feedClient, err := feed.NewClient(a.ctx, a.connection) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
getPackagesArgs := feed.GetPackagesArgs{ | ||
FeedId: &feedName, | ||
Project: &projectName, | ||
} | ||
return feedClient.GetPackages(a.ctx, getPackagesArgs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package azuredevops | ||
|
||
import ( | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/git" | ||
) | ||
|
||
// GetPackageVersion gets all GitRepository | ||
func (a *AzureDevOps) GetFileContent(projectName string, repoName string, version string) (*git.GitItem, error) { | ||
client, err := git.NewClient(a.ctx, a.connection) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
path := "README.md" | ||
includeContent := true | ||
gitVersionDescriptor := git.GitVersionDescriptor{ | ||
VersionType: &git.GitVersionTypeValues.Tag, | ||
Version: &version, | ||
} | ||
getItemArgs := git.GetItemArgs{ | ||
RepositoryId: &repoName, | ||
Project: &projectName, | ||
Path: &path, | ||
IncludeContent: &includeContent, | ||
VersionDescriptor: &gitVersionDescriptor, | ||
} | ||
return client.GetItem(a.ctx, getItemArgs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package azuredevops | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/location" | ||
) | ||
|
||
// GetIdentityId gets the UUID of the authenticated user. Yes this is weird, see https://github.com/microsoft/azure-devops-python-api/issues/188#issuecomment-494858123 | ||
func (a *AzureDevOps) GetIdentityId() (*uuid.UUID, error) { | ||
client := location.NewClient(a.ctx, a.connection) | ||
|
||
self, err := client.GetConnectionData(a.ctx, location.GetConnectionDataArgs{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return self.AuthenticatedUser.Id, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package azuredevops | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/core" | ||
) | ||
|
||
// getProjectUUID gets the UUID of a project | ||
func (a *AzureDevOps) getProjectUUID(projectName string) (*uuid.UUID, error) { | ||
client, err := core.NewClient(a.ctx, a.connection) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
getProjectsArgs := core.GetProjectsArgs{} | ||
projects, err := client.GetProjects(a.ctx, getProjectsArgs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, project := range *&projects.Value { | ||
if *project.Name == projectName { | ||
return project.Id, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("project %s not found", projectName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package azuredevops | ||
|
||
import ( | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/git" | ||
"github.com/microsoft/azure-devops-go-api/azuredevops/wiki" | ||
) | ||
|
||
func (a *AzureDevOps) CreateWikiIfNotExists(projectName string, wikiName string, gitEmail string, gitUsername string, adoPat string) (*string, error) { | ||
client, err := wiki.NewClient(a.ctx, a.connection) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
getWikiArgs := wiki.GetWikiArgs{ | ||
Project: &projectName, | ||
WikiIdentifier: &wikiName, | ||
} | ||
|
||
r, localPath, err := createRepositoryIfNotExists(a, projectName, wikiName, gitEmail, gitUsername, adoPat) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = client.GetWiki(a.ctx, getWikiArgs) | ||
|
||
if err == nil { | ||
return localPath, nil | ||
} | ||
|
||
projectId, err := a.getProjectUUID(projectName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
branch := "main" | ||
mappedPath := "/" | ||
wikiCreateArgs := wiki.CreateWikiArgs{ | ||
Project: &projectName, | ||
WikiCreateParams: &wiki.WikiCreateParametersV2{ | ||
MappedPath: &mappedPath, | ||
Name: &wikiName, | ||
ProjectId: projectId, | ||
Type: &wiki.WikiTypeValues.CodeWiki, | ||
RepositoryId: r.Id, | ||
Version: &git.GitVersionDescriptor{ | ||
VersionType: &git.GitVersionTypeValues.Branch, | ||
Version: &branch, | ||
}, | ||
}, | ||
} | ||
_, err = client.CreateWiki(a.ctx, wikiCreateArgs) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return localPath, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package external_git | ||
|
||
// HasChanges checks for changes in the current branch | ||
func (g *ExternalGit) HasChanges() (bool, error) { | ||
var args []string | ||
args = []string{"status", "-s"} | ||
|
||
content, err := g.Exec(args...) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if content == "" { | ||
return false, nil | ||
} | ||
|
||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package external_git |