Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Demonstrating Data to Knowledge Pipelines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leon Michel Gorißen
Demonstrating Data to Knowledge Pipelines
Commits
8f9ee6e6
Commit
8f9ee6e6
authored
1 year ago
by
Leon Michel Gorißen
Browse files
Options
Downloads
Patches
Plain Diff
Feat: Make git commit hash avialable
parent
96483246
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
coscine_watchdog/coscine_client.py
+25
-3
25 additions, 3 deletions
coscine_watchdog/coscine_client.py
with
25 additions
and
3 deletions
coscine_watchdog/coscine_client.py
+
25
−
3
View file @
8f9ee6e6
...
@@ -11,9 +11,9 @@ import coscine
...
@@ -11,9 +11,9 @@ import coscine
import
os
import
os
import
signal
import
signal
import
sys
import
sys
import
subprocess
# TODO create new coscine resource with new application profile once available
# TODO create new coscine resource with new application profile once available
# TODO add git commit to data
app
=
Flask
(
__name__
)
# Create a new Flask application
app
=
Flask
(
__name__
)
# Create a new Flask application
...
@@ -39,8 +39,30 @@ logger.addHandler(console_handler) # Add console handler to logger
...
@@ -39,8 +39,30 @@ logger.addHandler(console_handler) # Add console handler to logger
logger
.
addHandler
(
file_handler
)
# Add file handler to logger
logger
.
addHandler
(
file_handler
)
# Add file handler to logger
# Retrieve environment variables for API token and robot UUID
# Retrieve environment variables for API token and robot UUID
api_token
=
os
.
environ
.
get
(
"
COSCINE_API_TOKEN
"
)
# Get COSCINE_API_TOKEN from environment
def
get_env_variable
(
var_name
):
robot_uuid
=
os
.
environ
.
get
(
"
ROBOT_UUID
"
)
# Get ROBOT_UUID from environment
value
=
os
.
environ
.
get
(
var_name
)
if
value
is
None
:
raise
EnvironmentError
(
f
"
The environment variable
{
var_name
}
is not set.
"
)
return
value
try
:
api_token
=
get_env_variable
(
"
COSCINE_API_TOKEN
"
)
# Get COSCINE_API_TOKEN from environment
robot_uuid
=
get_env_variable
(
"
ROBOT_UUID
"
)
# Get ROBOT_UUID from environment
except
EnvironmentError
as
e
:
print
(
e
)
# Handle the error appropriately, e.g., exit the program or set default values
api_token
=
None
robot_uuid
=
None
try
:
# Run the git command to get the latest commit hash
result
=
subprocess
.
run
([
'
git
'
,
'
rev-parse
'
,
'
HEAD
'
],
check
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
text
=
True
)
# The commit hash will be in result.stdout
commit_hash
=
result
.
stdout
.
strip
()
except
subprocess
.
CalledProcessError
as
e
:
print
(
f
"
Error occurred while getting the latest git commit:
{
e
.
stderr
}
"
)
def
upload_coscine
(
filepath
:
Path
,
token
:
str
)
->
None
:
def
upload_coscine
(
filepath
:
Path
,
token
:
str
)
->
None
:
"""
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment