Skip to content

Commit

Permalink
added remove badge support and removed arc-summary.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerskk committed Jul 16, 2024
1 parent 302819d commit 6b06c8c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
13 changes: 7 additions & 6 deletions app/api/endpoints/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,22 @@ async def publish_project(request: Request, background_tasks: BackgroundTasks,

try:
archive_file = gitlab_api.get_job_artifact_arcjson(project_id=project.id, branch="main", filename="arc.json",
job_name="create ARC JSON")
summary_file = gitlab_api.get_job_artifact_md(project_id=project.id, branch="main",
filename="arc-summary.md", job_name="create ARC JSON")
job_name="Create ARC JSON")
# summary_file = gitlab_api.get_job_artifact_md(project_id=project.id, branch="main",
# filename="arc-summary.md", job_name="create ARC JSON")

except:
raise HTTPException(status_code=403, detail="Couldn't retrieve arc.json")

try:
invenio_api.start_draft_file_upload(record_id, ["arc.json", "arc-summary.md"])
# invenio_api.start_draft_file_upload(record_id, ["arc.json", "arc-summary.md"])
invenio_api.start_draft_file_upload(record_id, ["arc.json"])
invenio_api.upload_draft_content(record_id, "arc.json", json.dumps(archive_file))
invenio_api.complete_draft_upload(record_id=record_id, filename="arc.json")

# invenio_api.start_draft_file_upload(record_id, ["arc-summary.md"])
invenio_api.upload_draft_content(record_id, "arc-summary.md", summary_file)
invenio_api.complete_draft_upload(record_id=record_id, filename="arc-summary.md")
# invenio_api.upload_draft_content(record_id, "arc-summary.md", summary_file)
# invenio_api.complete_draft_upload(record_id=record_id, filename="arc-summary.md")

invenio_api.update_draft(record_id=record_id, record_model=record)

Expand Down
54 changes: 53 additions & 1 deletion app/gitlab/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,59 @@ def get_job_artifact_md(self, project_id: int, branch: str, filename: str, job_n
except requests.exceptions.RequestException as err:
print(err)

def list_projects(self):

def get_all_projects(self):
projects = []

path = "/projects"

api_url = f'{self.api_url}{self.api_path}{path}'

page = 1
per_page = 20

while True:
response = requests.get(api_url, timeout=5, headers=self.headers,
params={'page': page, 'per_page': per_page})

if response.status_code != 200:
raise Exception(f"Failed to fetch projects: {response.status_code} {response.text}")

# Get JSON response
data = response.json()

print("data", data)

# If no more projects, break the loop
if not data:
break

# if page == 3:
# break

# Add projects to the list
projects.extend(data)

page += 1


project_list = ProjectList(projects=projects)
return project_list.projects




# Fetch all projects
all_projects = get_all_projects()

# Print project names
for project in all_projects:
print(project['name'])




def list_projects_old(self):
path = "/projects/"

api_url = f'{self.api_url}{self.api_path}{path}'
Expand Down
2 changes: 1 addition & 1 deletion app/tasks/setup/add_badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def delete_project_badge(project_id: int):
gitlab_url = os.getenv("GITLAB_URL", "http://localhost")
archigator_url = os.getenv("ARCHIGATOR_URL", "http://localhost:8000")

preinstall_badges = ["publish-badge"]
preinstall_badges = ["publish-badge","auto-badge"]

print("in setup project", project_id)
gitlab_api = Gitlab_API()
Expand Down
7 changes: 3 additions & 4 deletions app/tasks/setup/setup_all_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ def delete_badges():
print("in deleting badges")
gitlab_api = Gitlab_API()

projects_list = gitlab_api.list_projects()
print("getting obejects")
projects_list = gitlab_api.get_all_projects()


projectid_list = []

for projects in projects_list:
projectid_list.append(projects.id)

print("project_idlist", projectid_list)
# print(projects.id)


for project in projects_list:
print(project.id)
delete_project_badge(project_id=project.id)


Expand Down

0 comments on commit 6b06c8c

Please sign in to comment.