Skip to content

Commit

Permalink
Merge pull request #11 from iv-mexx/feature/migrateSnippets
Browse files Browse the repository at this point in the history
Migrate snippets
  • Loading branch information
iv-mexx authored Nov 28, 2016
2 parents fa713ac + bb198d6 commit 916600c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,21 @@ I've put this into my `~/.zshrc` (because I did not find out how else to set thi
* labels
* notes (see caveats)
### Snippets
* project
* name
* filename
* code
* notes (see caveats)
* ❗️author is not migrated
* author of the new snippet is the user thats performing the migration
* ❗️visibility level is not migrated
* snippets will be created with visibility level = 'internal'
## Whats not being migrated
* Merge Requests + Notes
* Snippets + Notes
* System Hooks
* Users
Expand Down
26 changes: 26 additions & 0 deletions fastlane/actions/gitlab_create_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def self.run(params)
# Create Issues
migrate_issues(source, destination, original_project, new_project, user_mapping, milestone_mapping)

# Create Snippets
migrate_snippets(source, destination, original_project, new_project, user_mapping)

new_project
end

Expand Down Expand Up @@ -101,6 +104,29 @@ def self.migrate_labels(gitlab_src, gitlab_dst, project_src, project_dst)
Helper.log.info("Labels created")
end

def self.migrate_snippets(gitlab_src, gitlab_dst, project_src, project_dst, user_mapping)
Helper.log.info("Migrating snippets")
snipptes = gitlab_src.snippets(project_src.id).auto_paginate.each do |snippet|
code = gitlab_src.snippet_content(project_src.id, snippet.id)
new_snippet = gitlab_dst.create_snippet(project_dst.id, {
title: snippet.title,
file_name: snippet.file_name,
code: code,
visibility_level: 10
})
migrate_snippet_notes(gitlab_src, gitlab_dst, project_src, project_dst, snippet, new_snippet, user_mapping)
end
end

def self.migrate_snippet_notes(gitlab_src, gitlab_dst, project_src, project_dst, snippet_src, snippet_dst, usermap)
Helper.log.info("Migrating snippet notes for snippet #{snippet_src.id}")
gitlab_src.snippet_notes(project_src.id, snippet_src.id).auto_paginate.sort { |n1, n2| n1.id <=> n2.id }.each do |note |
body = "_Original comment by #{note.author.username} on #{Time.parse(note.created_at).strftime("%d %b %Y, %H:%M")}_\n\n---\n\n#{note.body}"
gitlab_dst.create_snippet_note(project_dst.id, snippet_dst.id, body)
end
Helper.log.info("Migrated snippet notes for snippet #{snippet_src.id}")
end

# Reads all deploy-keys from the source project and create them in the destination project
def self.migrate_deploy_keys(gitlab_src, gitlab_dst, project_src, project_dst)
Helper.log.info("Creating Deploy-Keys")
Expand Down

0 comments on commit 916600c

Please sign in to comment.