Skip to content
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

Azure DevOps mounter #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions lib/glue/mounters/azdo_mounter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'glue/mounters/base_mounter'
require 'fileutils'

class Glue::AzDOMounter < Glue::BaseMounter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe think on a more clear name? AzureGitMounter maybe?


Glue::Mounters.add self

def initialize trigger, options
super(trigger)
@options = options
@name = "AzDO Git"
@description = "Pull a repo."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@description = "Pull a repo."
@description = "Pull a repository from Azure DevOps"

end

def mount target
base = @options[:working_dir]

Glue.debug "Making base."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it stay here?

FileUtils.mkdir_p base

# Grab the path used as git url, excluding PAT.
# format of this target must be https://DUMMY:<PAT_TOKEN>@dev.azure.com/<account>/<project>/_git/<repository>
protocol, azdo_domain, account, project, repository = target.match(/\A(.*\/\/).*@(.*)\/(.*)\/(.*)\/_git\/(.+?)[\/]{0,1}\z/i).captures
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe get these parameters separately and build the URL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking on maybe having PATTOKEN as a configuration parameter, as can be useful for something else (working on creating work items on Azure DevOps, like the ones for Jira, Pivotal...)

Parameters I extract from the match are for building the folder name used for temporary storage, but the target url should be ````https://dev.azure.com/../../_git/....```

So that way, you can just use the Git Url you can copy/paste from Azure DevOps

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I see. Ok, so just move the PAT to paramter - which could also help in reducting it.


path = [azdo_domain, account, project, repository].map{|i| '/'+i}.join
working_target = File.expand_path(base + "" + path + "/")

Glue.notify "Cleaning directory: #{working_target}"
if ! Dir.exists? working_target
Glue.notify "#{working_target} is not a directory."
FileUtils.mkdir_p working_target
else
Glue.debug "Removing : #{working_target}"
FileUtils.rm_rf working_target
FileUtils.mkdir_p working_target
end
# result = `rm -rf #{working_target}`
# puts result
Glue.debug "Cloning into: #{working_target}"
result = `git clone -q #{target} #{working_target}`
# puts result
#end
return working_target
end

def supports? target
if target.include?("@dev.azure.com/") && target.include?("/_git/")
return true
else
return false
end
end

end
2 changes: 2 additions & 0 deletions lib/glue/mounters/url_mounter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def supports? target
last = target.slice(-4,target.length)
if last === ".git"
return false
elsif target.include?("@dev.azure.com/") && target.include?("/_git/")
return false
elsif start === "http"
return true
else
Expand Down