Skip to content

Commit

Permalink
renamed actions to activities; cleaned up plugins a little and added …
Browse files Browse the repository at this point in the history
…a plugin alias helper function which uses the filename as plugin name; removed unnecessary plugin test code protontypes#164
  • Loading branch information
kikass13 committed Oct 24, 2020
1 parent 9745229 commit 133164d
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from libreselery.configuration import LibreSeleryConfig
from libreselery.contribution_distribution_engine_types import (
Contributor,
ContributionAction,
ContributionActionPlugin,
ContributionActivity,
ContributionActivityPlugin,
)

### Start User Imports
Expand All @@ -18,7 +18,7 @@
##################################################################################


class GitFileContributionAction(ContributionActionPlugin):
class GitFileContributionActivity(ContributionActivityPlugin):
"""
This class is a plugin containing the implementation of a single ContributorAction.
It is responsible for gathering contributor information and evaluating scores
Expand All @@ -29,24 +29,24 @@ class GitFileContributionAction(ContributionActionPlugin):
contributors of local files (under git version control).
"""

_alias_ = "git_file_contribution_action"
_alias_ = ContributionActivityPlugin.pluginNameFromFileName(__file__)

def __init__(self):
super(GitFileContributionAction, self).__init__()
super(GitFileContributionActivity, self).__init__()

def initialize_(self, action):
def initialize_(self, activity):
"""
Overload of abstract method which is responsible for initializing this plugin
Parameters:
action (ContributionAction):
action object which contains all necessary information of what
activity (ContibutionActivity):
activity object which contains all necessary information of what
a contributor has to doto be scored and recognized as such
Returns:
bool: True if successfully initialized
"""
self.fileFilters = action.applies_to
self.fileFilters = activity.applies_to
return True

def onGlobalsUpdate_(self):
Expand Down Expand Up @@ -97,7 +97,7 @@ def gather_(self, cachedContributors=[]):
contributors, linesOfCode = ([c for c, s in blob], [s for c, s in blob])
### convert linesOfCode to score
### we need to use given metrics for that
### our action was initialized with a metric, we have to use that instead of
### our activity was initialized with a metric, we have to use that instead of
### doing something random here
###
### in this simple example, each line of code represents 0.25 score points
Expand All @@ -118,10 +118,10 @@ def execGit(self):
### get toplevel git dir path
### git rev-parse --git-dir
### --show-toplevel gives path without .git
self.log("Finding .git of '%s' ..." % self.directory)
self.log("Finding .git in '%s' ..." % self.directory)
cmds = [
"git",
"-C %s" % self.directory, ## run command as if in -C dir
"-C %s" % self.directory, ## run command as if in -C dir
"rev-parse --absolute-git-dir", ### get .git dir of toplevel repo
]
cmd = " ".join(cmds)
Expand Down Expand Up @@ -152,7 +152,7 @@ def execGit(self):
stdout, stderr = ps.communicate()
if not stderr:
### encode output
project = stdout.decode("utf-8")
project = stdout.decode("utf-8").strip()
if not project:
raise Exception("This is not a git repository!")
self.log("Found: '%s'" % project)
Expand Down Expand Up @@ -202,10 +202,14 @@ def execGit(self):
### filter out unwanted users, for example the one git blame adds
### in case there are uncommitted changes
### "<not.committed.yet>", "Not Committed Yet"
badContributor = Contributor("Not Committed Yet", "not.committed.yet")
badContributor = Contributor(
"Not Committed Yet", "not.committed.yet"
)
if badContributor in fileContributorDict:
del fileContributorDict[badContributor]
fileContributions[file] = fileContributorDict
else:
self.log(stderr)
return fileContributions

def processFileContributorDict(self, fcDict):
Expand Down Expand Up @@ -279,37 +283,28 @@ def parseBlame(self, lines, project):
def test():
success = False
print("This is a Test!")
### define our input configuration (action) which normally comes from .yml configuration
### define our input configuration (activity) which normally comes from .yml configuration
d = {
"contributions_to_code": {
"debug": True,
"type": "git_file_contribution_action", ### type of action (also the name of the plugin _alias_ used!)
"applies_to": [
"*.py",
], ### simple filter, not really thought out yet
"metrics": [ ### metrics applied to this action, what gets score and what doesnt
{
"UNIFORM": { ### metric identifier
"degradation_type": "linear",
"degradation_value": 1,
}
}
],
### type of activity (also the name of the plugin _alias_ used!)
"type": ContributionActivityPlugin.pluginNameFromFileName(__file__),
"applies_to": ["*.py"], ### simple filter, not really thought out yet
}
}
### create an action object
action = ContributionAction(d)
### create an activity object
activity = ContributionActivity(d)
### initialize the action
### which will in turn use this specific plugin
### if configured correctly
init = action.initialize_()
init = activity.initialize_()
### emulate some global information
### which is used by the plugin to work properly
config = LibreSeleryConfig({"directory": os.getcwd()})
action.updateGlobals(config=config, connectors=None)
activity.updateGlobals(config=config, connectors=None)
if init:
### let us do our work
contributors, scores = action.gather_()
contributors, scores = activity.gather_()
### visualize and finalize gathered data
print("Result:")
print("contributors:\n%s" % contributors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from libreselery import selery_utils
from libreselery.contribution_distribution_engine_types import (
Contributor,
ContributionAction,
ContributionActionPlugin,
ContributionActivity,
ContributionActivityPlugin,
)

### Start User Imports
Expand All @@ -21,9 +21,9 @@
##################################################################################


class GithubRemoteContributorsAction(ContributionActionPlugin):
class GithubRemoteContributorsActivity(ContributionActivityPlugin):
"""
This class is a plugin containing the implementation of a single ContributorAction.
This class is a plugin containing the implementation of a single ContributorActivity.
It is responsible for gathering contributor information and evaluating scores
for each contributor based on configurated metrics
Expand All @@ -32,28 +32,28 @@ class GithubRemoteContributorsAction(ContributionActionPlugin):
contributors of local files (under git version control).
"""

_alias_ = "github_remote_contributors_action"
_alias_ = ContributionActivityPlugin.pluginNameFromFileName(__file__)
GITHUB_CONNECTOR_NAME = "github"

def __init__(self):
super(GithubRemoteContributorsAction, self).__init__()
super(GithubRemoteContributorsActivity, self).__init__()

def initialize_(self, action):
def initialize_(self, activity):
"""
Overload of abstract method which is responsible for initializing this plugin
Parameters:
action (ContributionAction):
action object which contains all necessary information of what
activity (ContributionActivity):
activity object which contains all necessary information of what
a contributor has to doto be scored and recognized as such
Returns:
bool: True if successfully initialized
"""
init = True
self.uniform_score = action.readParam("uniform_score")
self.min_contributions = action.readParam("min_contributions", default=0)
self.include_deps = action.readParam("include_dependencies", default=False)
self.uniform_score = activity.readParam("uniform_score")
self.min_contributions = activity.readParam("min_contributions", default=0)
self.include_deps = activity.readParam("include_dependencies", default=False)
init = False if not self.uniform_score or not self.min_contributions else True
return init

Expand All @@ -73,9 +73,9 @@ def onGlobalsUpdate_(self):
###
### TODO:
### these config values should probably not come from globals()
### but from action (self.initialize_) instead
### but from activity (self.initialize_) instead
### because they are not global anymore and instead
### define this specific action
### define this specific activity
self.include_main_repository = self.getGlobals().include_main_repository

### get current github connector
Expand All @@ -92,7 +92,7 @@ def onGlobalsUpdate_(self):
def gather_(self, cachedContributors=[]):
"""
Overload of abstract method which is responsible for gathering
contributor information and scoring contributors based on the action defined
contributor information and scoring contributors based on the activity defined
Parameters:
[optional] cachedContributors (list):
Expand Down Expand Up @@ -163,7 +163,6 @@ def gatherProjectDeps(self, project):
scores = []
### do stuff to include deps contributors as well
### ...
self.log("XAXA")
return contributors, scores

def validateContributors(self, contributors):
Expand Down Expand Up @@ -209,31 +208,29 @@ def test_grabEnvironmentVarsFromFile(path):
def test():
success = False
print("This is a Test!")
### define our input configuration (action) which normally comes from .yml configuration
### define our input configuration (activity) which normally comes from .yml configuration
d = {
"contributions_from_github": {
"debug": True,
"type": "github_remote_contributors_action", ### type of action (also the name of the plugin _alias_ used!)
### type of activity (also the name of the plugin _alias_ used!)
"type": ContributionActivityPlugin.pluginNameFromFileName(__file__),
"params": {
"min_contributions": 1,
"uniform_score": 30,
"include_dependencies": True,
},
"metrics": [ ### metrics applied to this action, what gets score and what doesnt
{"UNIFORM": {}} ### metric identifier
],
}
}
### create an action object
action = ContributionAction(d)
### initialize the action
### create an activity object
activity = ContributionActivity(d)
### initialize the activity
### which will in turn use this specific plugin
### if configured correctly
init = action.initialize_()
init = activity.initialize_()
### emulate some global information
### which is used by the plugin to work properly
test_grabEnvironmentVarsFromFile(
os.path.join(os.environ["HOME"], ".openselery/tokens.env")
os.path.join(os.environ["HOME"], ".libreselery/tokens.env")
)
myGithubToken = os.environ["GITHUB_TOKEN"]
connectors = {"github": GithubConnector(myGithubToken)}
Expand All @@ -243,10 +240,10 @@ def test():
"include_main_repository": True,
}
)
action.updateGlobals(config=config, connectors=connectors)
activity.updateGlobals(config=config, connectors=connectors)
if init:
### let us do our work
contributors, scores = action.gather_()
contributors, scores = activity.gather_()
### visualize and finalize gathered data
print("Result:")
print("contributors:\n%s" % contributors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from libreselery.configuration import LibreSeleryConfig
from libreselery.contribution_distribution_engine_types import (
Contributor,
ContributionAction,
ContributionActionPlugin,
ContributionActivity,
ContributionActivityPlugin,
)

### Start User Imports
Expand All @@ -16,30 +16,30 @@
##################################################################################


class MY_TEST_ACTION_PLUGIN_CLASS(ContributionActionPlugin):
class MY_TEST_ACTIVITY_PLUGIN_CLASS(ContributionActivityPlugin):
"""
This class is a plugin containing the implementation of a single ContributorAction.
This class is a plugin containing the implementation of a single ContributorActivity.
It is responsible for gathering contributor information and evaluating scores
for each contributor based on configurated metrics
Plugin description:
This plugin does nothing special, it's just for testing and showcasing how
to use and implement plugins in the action lifecycle of the CDE.
to use and implement plugins in the activity lifecycle of the CDE.
It will just return a random contributor list and some randome scores.
"""

_alias_ = "test_action"
_alias_ = ContributionActivityPlugin.pluginNameFromFileName(__file__)

def __init__(self):
super(MY_TEST_ACTION_PLUGIN_CLASS, self).__init__()
super(MY_TEST_ACTIVITY_PLUGIN_CLASS, self).__init__()

def initialize_(self, action):
def initialize_(self, activity):
"""
Overload of abstract method which is responsible for initializing this plugin
Parameters:
action (ContributionAction):
action object which contains all necessary information of what
activity (ContributionActivity):
activity object which contains all necessary information of what
a contributor has to doto be scored and recognized as such
Returns:
Expand All @@ -66,7 +66,7 @@ def onGlobalsUpdate_(self):
def gather_(self, cachedContributors=[]):
"""
Overload of abstract method which is responsible for gathering
contributor information and scoring contributors based on the action defined
contributor information and scoring contributors based on the activity defined
Parameters:
[optional] cachedContributors (list):
Expand Down Expand Up @@ -101,27 +101,28 @@ def gather_(self, cachedContributors=[]):
def test():
success = False
print("This is a Test!")
### define our input configuration (action) which normally comes from .yml configuration
### define our input configuration (activity) which normally comes from .yml configuration
d = {
"test_action_id": {
"test_activity_id": {
"debug": True,
"type": "test_action", ### type of action (also the name of the plugin _alias_ used!)
### type of activity (also the name of the plugin _alias_ used!)
"type": ContributionActivityPlugin.pluginNameFromFileName(__file__),
}
}
### create an action object
action = ContributionAction(d)
### create an activity object
activity = ContributionActivity(d)
### initialize the action
### which will in turn use this specific plugin
### if configured correctly
init = action.initialize_()
init = activity.initialize_()
### emulate some global information
### which is used by the plugin to work properly
config = LibreSeleryConfig({"simulation": True})
action.updateGlobals(config=config, connectors=None)
activity.updateGlobals(config=config, connectors=None)
### preparations done, lets do something
if init:
### let us do our work
contributors, scores = action.gather_()
contributors, scores = activity.gather_()
### visualize and finalize gathered data
print("Result:")
print("contributors:\n%s" % contributors)
Expand Down
Loading

0 comments on commit 133164d

Please sign in to comment.