Skip to content

Continue projectsv2 support#6735

Merged
samcoe merged 17 commits intocli:trunkfrom
qoega:continue-projectsv2
Jan 19, 2023
Merged

Continue projectsv2 support#6735
samcoe merged 17 commits intocli:trunkfrom
qoega:continue-projectsv2

Conversation

@qoega
Copy link
Contributor

@qoega qoega commented Dec 15, 2022

This PR continues PR #6043 from another contributor.
Original fork is currently unavailable and I restored changes in separate one.

Rebased and fixed tests as they were reworked since last PR change.

Note: Currently I had to manually run gh auth refresh -s project to make it work. Probably it makes sense to add project scope to default scopes.

Original PR description from #6043

Creating Issue/PR

Collect all IDs for repository's and organization's projects V2 and store them in the repo metadata to suport ID resolution.
All extracted IDs for legacy/old/v1 projects are fed as an input for IssueCreate/PullRequestCreate mutation.
All extracted IDs for new/v2 projects will are used to create AddProjectV2ItemById/DeleteProjectV2Item mutation.
All collected projectV2 names are also used as hints in the interactive mode.
Editing Issue/PR

Collect all IDs for repository's and organization's projects V2 and store them in the repo metadata to support ID resolution.
Gather all item IDs corresponding to the edited entity to provide hints to which projects entity belongs and to support mapping of public ID to a project-specific item ID.
Updating projects linked happens in two steps: 1) add item to all new projects and 2) remove item from all projects which are no longer needed.
3.1. all projects which are in the current selection, but to which the item does not belong, should be added.
3.2. all projects which are not in the current selection, but to which the item belongs, should be removed.
Notes: I am a bit lost with regards to the expected level of testing and could use some guidance here. I ensured that existing tests pass with expected reasons. I ensured that correct APIs are called when project V2 items are impacted. I also did some manual testing of (non-)interactive modes on my own repo and projects. I would like to have more automated testing, but am a bit lost in the current setup.

Fixes #4547

pshevche and others added 11 commits December 14, 2022 14:59
Adding methods similar to RepoProjects and OrganizationProjects to
collect a list of RepoProjectV2. In constrast to projects old/v1, we
cannot query projects by state. So, we filter out closed projects
after fetching them.
With this change, project names are now mapped to a pair of ID lists.
The first one contains IDs of old/v1 projects and the second contains
the IDs of next/v2 projects. This allows us to exclude projectV2 IDs
from IssueCreate and PullRequestCreate mutations and in the future,
would allow us to include only projectV2 IDs in the addProjectV2ItemById
mutation.
If creating the entity succeeded, then we add it by ID to all V2
projects. This will require triggering a mutation per project.
In constrast to regular field update, we track additions and deletions
separately, since project items can be added to and remove from project,
but not in a single mutation. To add item (i.e. issue or PR) to a
project V2, we call AddProjectV2ItemById with the entity's ID and
project's ID. Removing the item from a project is more tricky. The item
known to the project does not correspond to an ID of an issue or PR.
Instead, we firstly fetch all known item IDs that correspond to the
issue or PR, and then remove those from all projects that are requested
to be removed.
Prior to this commit, only projectV1 names were provided as hints when
using interactive suvery. Now, projectV2 titles are also included in
the proposal.
@qoega qoega requested a review from a team as a code owner December 15, 2022 09:59
@qoega qoega requested review from mislav and removed request for a team December 15, 2022 09:59
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Dec 15, 2022
@samcoe samcoe self-assigned this Jan 9, 2023
@samcoe samcoe self-requested a review January 9, 2023 19:33
Handle if project scope does not exist
Handle if host does not support projectsV2
@samcoe
Copy link
Contributor

samcoe commented Jan 12, 2023

@qoega Thanks for the contribution and getting this work started. I pushed a couple commits that made these changes:

  • Make a single request with multiple mutations for editing project items
  • Add handling for if the user does not have appropriate auth scopes
  • Add handling for GHES versions that do not support projectsV2
  • Simplified some of the implementation and reduced changes to function calls
  • Updated tests accordingly

@qoega
Copy link
Contributor Author

qoega commented Jan 12, 2023

Thank you. I just resurrected contributon from @pshevche #6043

@pshevche
Copy link
Contributor

@samcoe , @qoega , thank you both for getting this change into a better shape. Sorry for abandoning it, other things got in the way and I did not have time to keep the PR up-to-date.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Thanks for the hard work @samcoe and contributors! 🎉

return nil, fmt.Errorf("error fetching projectsV2: %w", err)
}

orgProjectsV2, err := OrganizationProjectsV2(client, repo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: repo projects and organization projects could be looked up in parallel with each other, since they're orthogonal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that we could do that but because of how this function is used in RepoMetadata function this change would be require adding some synchronization code around result.ProjectsV2 in RepoMetadata which would add a good amount of complexity for what seems like fairly little payoff. If we notice this is slow or receive complaints then we can optimize this further.

if v, ok := inputs["teamIds"]; ok {
t.Errorf("did not expect teamIds: %v", v)
}
assert.NotContains(t, inputs, "userIds")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL NotContains!

@samcoe samcoe enabled auto-merge (squash) January 19, 2023 22:02
@samcoe samcoe merged commit 179e9c2 into cli:trunk Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue commands do not work with non-classic Projects

5 participants