Skip to content

Commit d12f04e

Browse files
authored
Merge pull request #371 from openforcefield/fix-fetch-project-board
Fix error cycling
2 parents 465923a + 56a3b69 commit d12f04e

File tree

4 files changed

+124
-14
lines changed

4 files changed

+124
-14
lines changed

.github/workflows/lifecycle-error-cycle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
4949
- name: Run lifecycle processing script
5050
env:
51-
GH_TOKEN: ${{ secrets.GH_DANGERBOT_TOKEN_LIMITED }}
51+
GH_TOKEN: ${{ secrets.QCA_DATASET_SUBMISSION_PAT }}
5252
QCA_USER: ${{ secrets.QCA_USER }}
5353
QCA_KEY: ${{ secrets.QCA_KEY }}
5454
run: |

management/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
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
2+
* org:project:(read and write) access
3+
* repo:pull request:(read and write) access
4+
5+
This token is accessed via the `QCA_DATASET_SUBMISSION_PAT` secret.
6+
7+
These tokens must be renewed periodically as GH only permits them a max lifetime of 1 year.

management/lifecycle.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _get_board_card_state(board, pr):
107107
pr_card = None
108108
for state, cards in board.items():
109109
for card in cards:
110-
if card.pr_number == pr.number:
110+
if int(card.pr_number) == int(pr.number):
111111
pr_state = state
112112
pr_card = card
113113
break
@@ -809,17 +809,17 @@ def create_dataset(dataset_data):
809809
raise RuntimeError(f"The dataset type {dataset_type} is not supported.")
810810

811811

812-
def _get_full_board(repo):
813-
proj = [proj for proj in repo.get_projects() if proj.name == "Dataset Tracking"][0]
814-
board = {col.name: [card for card in col.get_cards()] for col in proj.get_columns()}
815-
816-
# attach pr number to each card; we do this *once* here to avoid too many API calls,
817-
# exhausting our limit
818-
for col, cards in board.items():
819-
for card in cards:
820-
card.pr_number = card.get_content().number
821-
822-
return board
812+
# def _get_full_board(repo):
813+
# proj = [proj for proj in repo.get_projects() if proj.name == "Dataset Tracking"][0]
814+
# board = {col.name: [card for card in col.get_cards()] for col in proj.get_columns()}
815+
#
816+
# # attach pr number to each card; we do this *once* here to avoid too many API calls,
817+
# # exhausting our limit
818+
# for col, cards in board.items():
819+
# for card in cards:
820+
# card.pr_number = card.get_content().number
821+
#
822+
# return board
823823

824824

825825
def _get_tracking_prs(repo):
@@ -928,7 +928,9 @@ def main():
928928

929929
# grab the full project board state once so we don't have to hammer the API
930930
# over and over
931-
board = _get_full_board(repo)
931+
#board = _get_full_board(repo)
932+
import projectsv2
933+
board = projectsv2._get_full_board()
932934

933935
# for each PR, we examine the changes to find files used for the submission
934936
# this is where the mapping is made between the PR and the submission files

management/projectsv2.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import os
2+
import requests
3+
4+
5+
class ProjectV2Project(dict):
6+
def __init__(self, project_node_id):
7+
self.project_node_id = project_node_id
8+
data = self._get_project_data("PVT_kwDOARrkss4Am84U")
9+
print(data)
10+
self.columns = dict()
11+
for item in data['data']['node']['items']['nodes']:
12+
for field in item['fieldValues']['nodes']:
13+
if 'name' in field:
14+
column_name = field['name']
15+
if column_name not in self.columns:
16+
self.columns[column_name] = ProjectV2Column(self,
17+
field['id'],
18+
column_name
19+
)
20+
self.columns[column_name].cards.append(ProjectV2PRCard(self,
21+
self.columns[column_name],
22+
item['id'],
23+
item['content']['url'],
24+
item['content']['title']
25+
))
26+
print(column_name, field['id'])
27+
28+
def _get_project_data(self, project_node_id):
29+
query = """
30+
query {
31+
node(id: "%s") {
32+
... on ProjectV2 {
33+
items(first: 100) {
34+
nodes {
35+
id
36+
content {
37+
__typename
38+
... on Issue {
39+
title
40+
url
41+
}
42+
... on PullRequest {
43+
title
44+
url
45+
}
46+
}
47+
fieldValues(first: 10) {
48+
nodes {
49+
... on ProjectV2ItemFieldSingleSelectValue {
50+
name
51+
id
52+
}
53+
}
54+
}
55+
}
56+
pageInfo {
57+
hasNextPage
58+
endCursor
59+
}
60+
}
61+
}
62+
}
63+
}
64+
""" % project_node_id
65+
66+
headers = {"Authorization": f"Bearer {os.environ['GH_TOKEN']}"}
67+
response = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
68+
69+
data = response.json()
70+
return data
71+
72+
73+
class ProjectV2Column:
74+
def __init__(self, project, column_node_id, column_name):
75+
self.project = project
76+
self.column_node_id = column_node_id
77+
self.column_name = column_name
78+
self.cards = list()
79+
80+
81+
class ProjectV2PRCard:
82+
def __init__(self, project, column, card_node_id, card_url, card_name):
83+
self.project = project
84+
self.card_node_id = card_node_id
85+
self.card_url = card_url
86+
self.card_name = card_name
87+
88+
89+
def move(position, column):
90+
pass
91+
92+
93+
def _get_full_board():
94+
proj = ProjectV2Project("PVT_kwDOARrkss4Am84U")
95+
board = {col.column_name: [card for card in col.cards] for col in proj.columns.values()}
96+
97+
for col, cards in board.items():
98+
for card in cards:
99+
card.pr_number = card.card_url.split('/')[-1]
100+
101+
return board

0 commit comments

Comments
 (0)