Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

atlassian-connect-express 10: context parameters

Hello!
In this article we will continue to talk about atlassian-connect-express and we will talk about context parameters.

This article will be based on this article.

You can find the source code for the article here.

The video for the article you can watch here.

Context parameters are placeholders you can put into a module’s URL to have Bitbucket send contextual information with each request to that module.

For example, let’s have a look at our application. We have the following repoPages module in the atlassian-connect.json:

"repoPages": [
            {
                "url": "/connect-example?repoPath={repository.full_name}",
                "name": {
                    "value": "Example Page"
                },
                "location": "org.bitbucket.repository.navigation",
                "key": "example-repo-page",
                "params": {
                    "auiIcon": "aui-iconfont-doc"
                }
            }
        ],

Please, pay attention to the “url”: “/connect-example?repoPath={repository.full_name}” part. “repository” is a context parameter for which we take the full_name attribute and assign to the repoPath parameter in the url and we can read later this repoPath parameter in the code.

Ok, let’s set a breakpoint in the routes/index.html file and click on the “Example Page” menu option:

Screenshot 2021-06-06 at 08.41.31.png

The execution of our app will stop here:

Screenshot 2021-06-06 at 08.25.47.png

Now if you have a look at the Debug tab in the variables section, you will see that the repoPath url parameter was set with “alex1mmmcprime2/bb-test-app-repo” which is the full name of our repo.

Well, how would we know what context parameters we can use for our modules?

You can find this information here.

Screenshot 2021-06-06 at 08.38.10.png

As you can see for our repoPages module we have three context variable: target_user, repository and user. Target_user is the user under whom the plugin is installed, repository is the repository from which the Example Page menu item is called and user is the user who called the Example Page menu item.

The next question is how to understand what attributes I can use for each of the context parameters.

The answer is you can use any attribute from the corresponding REST endpoint.

For the target_user and the user context parameter the corresponding endpoint is users/{selected_users}, for the repository context parameter it is the repository/{workspace}/{repo_slug}.

Let’s have a look at the repository/{workspace}/{repo_slug} REST endpoint. Here is the schema:

Screenshot 2021-06-06 at 08.49.33.png

As you can see this endpoint has the “has_wiki” attribute and the “links.watchers.href” attribute. Let’s try to get this parameters in our app.

We will change the repoPages module to this one:

"repoPages": [
            {
                "url": "/connect-example?repoPath={repository.full_name}&repoHasWiki={repository.has_wiki}&repoLinksWatchers={repository.links.watchers.href}",
                "name": {
                    "value": "Example Page"
                },
                "location": "org.bitbucket.repository.navigation",
                "key": "example-repo-page",
                "params": {
                    "auiIcon": "aui-iconfont-doc"
                }
            }
        ],

And now if you update the application you will see that we can get our repoHasWiki and repoLinksWatchers url parameters in our app:

Screenshot 2021-06-06 at 08.58.28.png

That is how you can use context parameters.

Why do we need this parameters at all?

There are multiple cases. For example, you have some kind analytic system where you want to store user actions in your app. In this case you can get the name of the repo, the name of the user and save the values in your analytic system. Or you have some kind of integration with an external system and you need to pass the repo uuid to this external system. Or you want to log some information in the log file.

That is all for the article.

Have a good day!

1 comment

Mohammed Amine Community Leader Jun 08, 2021

Very interesting article

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Marketplace Apps & Integrations

☕️ Monday coffee with Jexo: Weekly Atlassian news roundup | 21st June 2021

Hi community 👋, as every Monday we're bringing you a quick update on what happened in the Atlassian ecosystem last week. There were a few interesting events like for example the announcement of th...

51 views 0 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you