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

Add support for classifying Compass API calls from @forge/graphql package with tests and testing parameters bug fix #66

Merged
merged 4 commits into from
Feb 28, 2025

Conversation

dxu2-atlassian
Copy link
Contributor

Add Compass asApp/asUser from default import: https://www.npmjs.com/package/@atlassian/forge-graphql

@jwong101
Copy link
Contributor

jwong101 commented Feb 13, 2025

Looks good so far. Just need to map public api methods from that package to scopes

@dxu2-atlassian dxu2-atlassian marked this pull request as ready for review February 26, 2025 17:20
}

// This is for handling https://developer.atlassian.com/cloud/compass/forge-graphql-toolkit/
fn load_compass_api_scopes() -> HashMap<String, Vec<String>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn load_compass_api_scopes() -> HashMap<String, Vec<String>> {
fn load_compass_api_scopes() -> HashMap<&'static str, Vec<&'static str>> {

strs created from include_str! are static, so you don't need to allocate new ones.

}

/// Retrieves permissions for a given key. Prints a warning if the key is missing.
pub fn get(&self, key: &str) -> Option<&Vec<String>> {
Copy link
Contributor

@jwong101 jwong101 Feb 26, 2025

Choose a reason for hiding this comment

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

Suggested change
pub fn get(&self, key: &str) -> Option<&Vec<String>> {
pub fn get(&self, key: &str) -> Option<&[String]> {

Generally speaking, it's usually better to return or accept slices instead of shared references to Vecs, since you can't do anything more with a &Vec besides reading the capacity of the buffer.

You can just change the signature of the function, and permissions should auto deref to match the slice return type.

If you want to do it manually, you can get a slice from a reference to a Vec by using Some(&**permissions) or Some(&permissions[..]).

// import graphqlGateway from "@atlassian/forge-graphql";
// const { errors, data} = await graphqlGateway.compass.asApp().getComponent({ componentId });
// [PropPath::Def(def), PropPath::Static(ref compass), ref auth
[PropPath::Def(def), PropPath::Static(ref compass), ref authn @ .., PropPath::Static(ref function_name)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you just match for PropPath::MemberCall directly here instead of using a slice pattern?

@dxu2-atlassian dxu2-atlassian changed the title Add support for classifying Compass API calls from the @forge/graphql package Add support for classifying Compass API calls from @forge/graphql package with tests and testing parameters bug fix Feb 27, 2025
@jwong101 jwong101 merged commit f085d62 into atlassian-labs:main Feb 28, 2025
4 checks passed
@dxu2-atlassian dxu2-atlassian deleted the feat/EAS-2646 branch February 28, 2025 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants