Skip to content

[WIP] GitLab addon#5929

Closed
danielneis wants to merge 81 commits intoCenterForOpenScience:developfrom
danielneis:feature/gitlab
Closed

[WIP] GitLab addon#5929
danielneis wants to merge 81 commits intoCenterForOpenScience:developfrom
danielneis:feature/gitlab

Conversation

@danielneis
Copy link
Contributor

@danielneis danielneis commented Jul 6, 2016

Purpose

Implement the GitLab addon according to the GitLab Integration Grant Spec at https://gist.github.com/felliott/cc3d48a492c174545b7f

Changes

"This add-on will allow users to specify a GitLab instance to communicate with, and then connect their GitLab account to their OSF account via an OAuth token. Users may then connect a project for which they have admin rights to one of their GitLab-hosted repositories. Users should also be able to change which repository is linked to a given project at any time and revoke permissions from any or all projects as desired."

Side effects

$ cat website/addons/gitlab/requirements.txt
cachecontrol==0.10.2
pyapi-gitlab==7.8.5
python-magic==0.4.6

Roadmap

  • Allow user to connect GitLab.com account to project
  • Fetch repositories from GitLab.com
  • Associate a repository from GitLab.com to a project
  • Browse files from default branch from repository
  • Browse files from any branch from repository
  • Create repository
  • List repository branches
  • Download default repository branch as tar file
  • Download any repository branch as tar file
  • Open repository on GitLab (link to correct branch)
  • File action: Download after change repository branch
  • File action: Download for default branch
  • File action: Delete from default branch
  • File action: Delete after change repository branch
  • File action: View
  • File action: View on GitLab.com
  • File action: Rename
  • Create folder on default branch (on root folder, and inside other folders)
  • Create folder on other branches (on root folder, and inside other folders)
  • Upload file to root folder on any branch
  • Upload file to any folder on non-default branch
  • Upload file to any folder on default branch
  • Allow user use another GitLab instance in projects
  • Tests
  • Documentation

Copy link
Member

@mfraezz mfraezz left a comment

Choose a reason for hiding this comment

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

A quick set of drive-by comments. Looking pretty good, but I have a few questions about whether or not everything copied from GitHub code is applicable to GitLab.

Please also get the TCI build passing.

Pass complete :octocat:


# Note: Even though GitLab supports file sizes over 1 MB, uploads and
# downloads through their API are capped at 1 MB.
MAX_FILE_SIZE = 100
Copy link
Member

Choose a reason for hiding this comment

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

If the above is correct, this should be 1, not 100

def user_repos(self, user):
return self.gitlab.getprojectsowned()

def my_org_repos(self, permissions=None):
Copy link
Member

Choose a reason for hiding this comment

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

Other than being mocked in tests, is this intended to be used anywhere?


:param str repo_id: GitLab repository id
:return: Dict of repo information
See #TODO: link gitlab docs
Copy link
Member

Choose a reason for hiding this comment

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

Please resolve TODO

user if omitted
:return dict: GitLab API response
"""
return self.gitlab.currentuser()
Copy link
Member

Choose a reason for hiding this comment

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

Here and elsewhere, if this outgoing request fails (e.g, due to invalid credentials), are any errors being handled gracefully?

:return: List of branch dicts
http://developer.github.com/v3/repos/#list-branches
"""
# TODO
Copy link
Member

Choose a reason for hiding this comment

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

TODO what?


<h4 class="addon-title">
<img class="addon-icon" src=${addon_icon_url}>
<span data-bind="text: properName"></span> <!-- TODO: Can we use mako addon_full_name as some other addons do? -->
Copy link
Member

Choose a reason for hiding this comment

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

TODO: Can we use mako addon_full_name

Probably, yes.



# TODO: Test remaining CRUD methods
# TODO: Test exception handling
Copy link
Member

Choose a reason for hiding this comment

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

Should these be done?

settings.repo = 'abc'
settings.user = 'octo-cat'

# TODO: allow changing the repo name
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary?

self.node_settings.owner.is_registration = True
assert_false(check_permissions(self.node_settings, self.consolidated_auth, connection, 'master'))

def check_hook_urls(self, urls, node, path, sha):
Copy link
Member

Choose a reason for hiding this comment

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

This probably won't be found by nosetests because the function name doesn't begin with test_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

urls = {}

if include_urls:
# TODO: Move to helper function
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary? It looks like the only other place it's happening is in a test, so I'd probably say it's not.

Copy link
Member

@felliott felliott left a comment

Choose a reason for hiding this comment

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

Hey @danielneis and @rafaeldelucena!

I'm sending this back for another pass. I hit a few issues trying to run it locally, most of which I think were caused by the Fangorn GitLab root object not having a .data.extra field. I've also made a note of which pieces can be removed in order to target a read-only provider first. We can add that back in after the read-only version is released. The other bit that will need updating when going read-only is the file editor that is constructed when viewing a file on the OSF. See this line from my Bitbucket PR.

Cheers,
@felliott

repo_id = fields.StringField()
hook_id = fields.StringField()
hook_secret = fields.StringField()
registration_data = fields.DictionaryField()
Copy link
Member

Choose a reason for hiding this comment

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

While working on the Bitbucket addon (also based off GitHub) I noticed this field registration_data and some code below that didn't make sense. It turns out this is code from a loooooooong, long time ago that doesn't do anything anymore and can be removed.

self.repo_id = None
self.hook_id = None
self.hook_secret = None
self.registration_data = None
Copy link
Member

Choose a reason for hiding this comment

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

See above. This can be deleted.

var m = require('mithril');
var $ = require('jquery');
var URI = require('URIjs');
var Fangorn = require('js/fangorn');
Copy link
Member

Choose a reason for hiding this comment

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

When you bring this up-to-date with develop-backup, you'll need to change this to var Fangorn = require('js/fangorn').Fangorn;

var buttons = [];
function _downloadEvent(event, item, col) {
event.stopPropagation();
var branch = tem.data.extra.ref || item.data.extra.fileSha;
Copy link
Member

Choose a reason for hiding this comment

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

typo: tem.data.extra.ref => item.data.extra.ref

Copy link
Member

Choose a reason for hiding this comment

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

If item is the root folder, it won't necessarily have a data.extra field. You'll need to check if it exists first. If it doesn't you can fallback to item.data.default_branch.

@@ -0,0 +1,10 @@
{
"gitlab_file_added" : "${user} added file ${path} to GitLab repo ${repo} in ${node}",
Copy link
Member

Choose a reason for hiding this comment

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

The ${repo} variable in this log message comes from website/static/js/logTextParser.js. That function is written specifically for github, so you'll need to add your own ${gitlab_repo} variable. I did the same thing for Bitbucket, you can see the examples here, here, and here.

// Cross browser key codes for the Command key
var commandKeys = [224, 17, 91, 93];

function _uploadUrl(item, file) {
Copy link
Member

Choose a reason for hiding this comment

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

Not needed for read-only.

return waterbutler.buildTreeBeardUpload(item, file, {branch: branch });
}

function _removeEvent (event, items) {
Copy link
Member

Choose a reason for hiding this comment

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

Not needed for read-only

}
if (tb.options.placement !== 'fileview') {
// If File and FileRead are not defined dropzone is not supported and neither is uploads
if (window.File && window.FileReader && item.data.permissions && item.data.permissions.edit) {
Copy link
Member

Choose a reason for hiding this comment

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

The 'Upload', 'Create Folder', and 'Delete' buttons can be removed from the read-only addon.

}, 'View'));
}
if (item.data.permissions && item.data.permissions.edit) {
buttons.push(
Copy link
Member

Choose a reason for hiding this comment

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

This button can be removed from the read-only provider.

}
}

if(item.data.provider && !item.data.isAddonRoot && item.data.permissions && item.data.permissions.edit && tb.options.placement !== 'fileview') {
Copy link
Member

Choose a reason for hiding this comment

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

'Rename' can be removed from the read-only provider.

@danielneis danielneis force-pushed the feature/gitlab branch 2 times, most recently from 10aca21 to 963e9e0 Compare April 10, 2017 14:19
@mfraezz mfraezz mentioned this pull request Jul 3, 2017
@mfraezz
Copy link
Member

mfraezz commented Jul 3, 2017

Closing in favor of #7418 , consider this merged. Thanks for all your hard work, @danielneis , @luismulinari , and @rafaeldelucena . :octocat:

@mfraezz mfraezz closed this Jul 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants