Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error cycling #371

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lifecycle-error-cycle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Run lifecycle processing script
env:
GH_TOKEN: ${{ secrets.GH_DANGERBOT_TOKEN_LIMITED }}
GH_TOKEN: ${{ secrets.QCA_DATASET_SUBMISSION_PAT }}
QCA_USER: ${{ secrets.QCA_USER }}
QCA_KEY: ${{ secrets.QCA_KEY }}
run: |
Expand Down
7 changes: 7 additions & 0 deletions management/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
For the GitHub automation to read and update the Dataset Tracking project board, it's necessary to make a Personal Access Token with the "resource owner" set to "openforcefield" available to the automation with at least
* org:project:(read and write) access
* repo:pull request:(read and write) access

This token is accessed via the `QCA_DATASET_SUBMISSION_PAT` secret.

These tokens must be renewed periodically as GH only permits them a max lifetime of 1 year.
28 changes: 15 additions & 13 deletions management/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _get_board_card_state(board, pr):
pr_card = None
for state, cards in board.items():
for card in cards:
if card.pr_number == pr.number:
if int(card.pr_number) == int(pr.number):
pr_state = state
pr_card = card
break
Expand Down Expand Up @@ -809,17 +809,17 @@ def create_dataset(dataset_data):
raise RuntimeError(f"The dataset type {dataset_type} is not supported.")


def _get_full_board(repo):
proj = [proj for proj in repo.get_projects() if proj.name == "Dataset Tracking"][0]
board = {col.name: [card for card in col.get_cards()] for col in proj.get_columns()}

# attach pr number to each card; we do this *once* here to avoid too many API calls,
# exhausting our limit
for col, cards in board.items():
for card in cards:
card.pr_number = card.get_content().number

return board
# def _get_full_board(repo):
# proj = [proj for proj in repo.get_projects() if proj.name == "Dataset Tracking"][0]
# board = {col.name: [card for card in col.get_cards()] for col in proj.get_columns()}
#
# # attach pr number to each card; we do this *once* here to avoid too many API calls,
# # exhausting our limit
# for col, cards in board.items():
# for card in cards:
# card.pr_number = card.get_content().number
#
# return board


def _get_tracking_prs(repo):
Expand Down Expand Up @@ -928,7 +928,9 @@ def main():

# grab the full project board state once so we don't have to hammer the API
# over and over
board = _get_full_board(repo)
#board = _get_full_board(repo)
import projectsv2
board = projectsv2._get_full_board()

# for each PR, we examine the changes to find files used for the submission
# this is where the mapping is made between the PR and the submission files
Expand Down
101 changes: 101 additions & 0 deletions management/projectsv2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os
import requests


class ProjectV2Project(dict):
def __init__(self, project_node_id):
self.project_node_id = project_node_id
data = self._get_project_data("PVT_kwDOARrkss4Am84U")
print(data)
self.columns = dict()
for item in data['data']['node']['items']['nodes']:
for field in item['fieldValues']['nodes']:
if 'name' in field:
column_name = field['name']
if column_name not in self.columns:
self.columns[column_name] = ProjectV2Column(self,
field['id'],
column_name
)
self.columns[column_name].cards.append(ProjectV2PRCard(self,
self.columns[column_name],
item['id'],
item['content']['url'],
item['content']['title']
))
print(column_name, field['id'])

def _get_project_data(self, project_node_id):
query = """
query {
node(id: "%s") {
... on ProjectV2 {
items(first: 100) {
nodes {
id
content {
__typename
... on Issue {
title
url
}
... on PullRequest {
title
url
}
}
fieldValues(first: 10) {
nodes {
... on ProjectV2ItemFieldSingleSelectValue {
name
id
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
""" % project_node_id

headers = {"Authorization": f"Bearer {os.environ['GH_TOKEN']}"}
response = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)

data = response.json()
return data


class ProjectV2Column:
def __init__(self, project, column_node_id, column_name):
self.project = project
self.column_node_id = column_node_id
self.column_name = column_name
self.cards = list()


class ProjectV2PRCard:
def __init__(self, project, column, card_node_id, card_url, card_name):
self.project = project
self.card_node_id = card_node_id
self.card_url = card_url
self.card_name = card_name


def move(position, column):
pass


def _get_full_board():
proj = ProjectV2Project("PVT_kwDOARrkss4Am84U")
board = {col.column_name: [card for card in col.cards] for col in proj.columns.values()}

for col, cards in board.items():
for card in cards:
card.pr_number = card.card_url.split('/')[-1]

return board
Loading